[R] Problem with global variable building a package

R. Michael Weylandt michael.weylandt at gmail.com
Tue Aug 7 20:35:02 CEST 2012


On Tue, Aug 7, 2012 at 2:09 AM, Eva Prieto Castro <evapcastro at yahoo.es> wrote:
>
>
> Hi,
>
>
>
> My name is
> Eva and this is my first message here. My English is not very good, but I hope
> you can understand my question, in the context of an academic project.
>
>
>
> I have
> developed several functions in R and the
> idea is that the user can access functions in order to:
>
>
>
> 1)
> Alter
> parameters in relation with data and type of analysis.
>
> 2)
> Run
> statistical analysis (Text and pdf files with results will be generated).
>
> 3)
> View
> the value of the most important parameters.
>
>
>
> All the
> parameters I need are stored in a list object, and this list is used in all the
> functions along the cycle performed by the user, but I would like the user does
> not need to pass the name of the list as argument when he/she runs the different
> functions, so I think I need to treat the list as a global variable.
>
>
>
> Firstly, I
> used the global assignment operator (“<<-“); secondly, I used “get” and “assign”
> functions and even I used a new.env() in order to use a new environment
> exclusively for my list. However, when I try to build a package with all my
> functions I don’t reach this end, because of an error in parse process.
>
>
>
> My question
> for you is the following: taking into account that my end is to build a
> package, what can I do with this “global” list?. How can I treat it?.

Hi Eva,

I was actually doing something similar just the other day -- for a
"quick and dirty" solution, you can use assignInNamespace() or
assignInMyNamespace() but the help pages suggest CRAN won't look
kindly thereupon. To avoid that, I simply used a hidden [starting with
a dot] variable in the user's global environment (i.e., I defined it
on package load with the .onAttach() function and then just referenced
it when needed) but the best practices solution is probably to use
options() or something similar. See, e.g., setCompilerOptions() of the
compiler package or setRmetricsOptions() of the Rmetrics bundle.

Best,
Michael


>
>
>
> Thanks in
> advance.
>
>
>
> Regards,
>
> Eva
>
>
>
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list