[R-pkg-devel] Assigning a variable to global environment

Matt Denwood md @end|ng |rom @und@ku@dk
Fri Dec 11 19:20:41 CET 2020


> On 11 Dec 2020, at 18:32, Tiago Olivoto <tiagoolivoto using gmail.com> wrote:
> 
> Hi everyone,
> This can be a very simple question, but I really have the following doubt.
> 
> CRAN Policies says that 'Packages should not modify the global environment
> (user’s workspace)'. So, may I or may I not create a function that will
> call internally the following code? (a simple example)
> 
> assign("name", 1, envir = .GlobalEnv)

You may not - and for good reason, as the user may have an existing variable called “name” that will be destroyed by such an action.  If you run "R CMD check —as-cran" on a package containing this code you will get a warning (or maybe a note, I can’t remember), and the package would most likely be refused if you tried to submit it to CRAN.

Cheers,

Matt


> 
> Cheers
> Tiago
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-package-devel&data=04%7C01%7Cmd%40sund.ku.dk%7C42392098d3324de389b008d89dfad39d%7Ca3927f91cda14696af898c9f1ceffa91%7C0%7C0%7C637433048371869663%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=NFTbsJDlZNQWajN%2F%2BeftuclrkJSGtTnM9kEtobn9VLs%3D&reserved=0



More information about the R-package-devel mailing list