Re: [R] function to avoid <<-

2014-12-05 Thread Henrik Bengtsson
Don't have your package "mess with" (e.g. assign) to the global environment. Also, CRAN won't accept such packages. A good rule of thumb is that if you find yourself using assign(), get(), and <<-, or assigning explicitly to the global environment, it's a good indicator that you're hiking up the w

Re: [R] function to avoid <<-

2014-12-05 Thread Karim Mezhoud
Hi, An other alternative using "assign" function func <- function(){ X <- 5 assign("X", X, envir = .GlobalEnv) } Ô__ c/ /'_;kmezhoud (*) \(*) ⴽⴰⵔⵉⵎ ⵎⴻⵣⵀⵓⴷ http://bioinformatics.tn/ On Tue, Dec 2, 2014 at 8:40 PM, Adams, Jean wrote: > Glad to see this query and the responses. You

Re: [R] function to avoid <<-

2014-12-02 Thread Adams, Jean
Glad to see this query and the responses. You all just helped me to eliminate the use of global variables from my R package. I knew they were not recommended, but I didn't know how to get around using them. Thanks! Jean On Tue, Dec 2, 2014 at 10:59 AM, Karim Mezhoud wrote: > OK thanks as: >

Re: [R] function to avoid <<-

2014-12-02 Thread Karim Mezhoud
OK thanks as: myenv <- new.env(parent = emptyenv()) fun <- function(){ fun1 <- function(){ myenv$X <- 5 } } fun() ls(myenv) #X X #5 Ô__ c/ /'_;kmezhoud (*) \(*) ⴽⴰⵔⵉⵎ ⵎⴻⵣⵀⵓⴷ http://bioinformatics.tn/ On Tue, Dec 2, 2014 at 5:47 PM, Greg Snow <538...@gmail.com> wrote: > By "At the t

Re: [R] function to avoid <<-

2014-12-02 Thread Greg Snow
By "At the top level" Hadley meant to put that code outside of the function definition. In you source file that line should be very near the top, before any function definitions. Then "myenv" will not be temporary (well it will go away when you end the R session). Further, when this code is comp

Re: [R] function to avoid <<-

2014-12-02 Thread Karim Mezhoud
Thanks Dr Hadley, but when I use a function the myenv remains temporary and I am to face the same problem. fun <- function(){ myenv <- new.env(parent = emptyenv()) fun1 <- function(){ myenv$X <- 5 } } ls(myEnv) #character(0) Ô__ c/ /'_;kmezhoud (*) \(*) ⴽⴰⵔⵉⵎ ⵎⴻⵣⵀⵓⴷ http://bioinfo

Re: [R] function to avoid <<-

2014-12-02 Thread Hadley Wickham
At the top level do: myenv <- new.env(parent = emptyenv()) Then in your functions do myenv$x <- 50 myenv$x etc You also should not be using data() in that way. Perhaps you want R/sysdata.rda. See http://r-pkgs.had.co.nz/data.html for more details. Hadley On Tue, Dec 2, 2014 at 2:28 AM, Karim

[R] function to avoid <<-

2014-12-02 Thread Karim Mezhoud
Dear All, I am writing a GUIpackage that needs global variables. I had many warning message when I checked the code as for example: geteSet: no visible binding for global variable ‘curselectCases’ I would like to write a function that creates a global place for Objects to be loaded as: Fun <- fu