floybix / latticist

Exploratory Visualisation GUI in R
2 stars 4 forks source link

CRAN checks: assignments to the global environment #13

Open landroni opened 10 years ago

landroni commented 10 years ago

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 commented 8 years ago

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 commented 8 years ago

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)