Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRAN checks: assignments to the global environment #13

Open
landroni opened this issue Oct 5, 2014 · 2 comments
Open

CRAN checks: assignments to the global environment #13

landroni opened this issue Oct 5, 2014 · 2 comments

Comments

@landroni
Copy link
Collaborator

landroni commented Oct 5, 2014

And the last item of the failed CRAN checks:

Found the following assignments to the global environment:
 File ‘latticist/R/latticeStyleGUI.R’:
   assign("trellis.par.theme", list(), globalenv())
   assign("trellis.par.log", list(), globalenv())
   assign("trellis.par.log", list(), globalenv())
   assign("trellis.par.theme", trellis.par.get(), globalenv())
   assign("trellis.par.theme", trellis.par.get(), globalenv())
   assign("trellis.par.log", tmplog, globalenv())
   assign("trellis.par.theme", trellis.par.get(), globalenv())
   assign("trellis.par.theme", trellis.par.get(), globalenv())
   assign("trellis.par.theme", trellis.par.get(), globalenv())

Are the assignments to globalenv() necessary? Can we avoid them?

@Bohdan-Khomtchouk
Copy link

Yes, it is necessary because it's basically doing the same thing that <<- would be doing... it's creating a global variable, and no such variable could possibly get created without the use of globalenv(). Clearly, instead of using the double assignment operator, the global variable is created using assign() with some extra options. Usually, instead of globalenv(), I use the simpler option envir = .GlobalEnv since it's more readable. Nevertheless, both your option and mine generate a NOTE during the CRAN check (e.g., using devtools::check()). I wonder if CRAN will eventually warm up to the idea of fully allowing this kind of call, without throwing a NOTE at us. I guess we'll have to wait and see. In any case, I'm submitting to Bioconductor soon, so I'll have to wait and see if they follow the same policy regarding this NOTE.

@Vladis466
Copy link

Vladis466 commented Jul 5, 2016

Any idea on why the following is accepted then? This does not trigger a note

pos <- 1
envir = as.environment(pos)
assign("trellis.par.theme", trellis.par.get(), envir = envir)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants