Thank Matt for your response.
Would be an acceptable solution to check if the variable exists first and
creating the new variable with a suffix? Please, see the following example
var_name <- "name"
var_name <- ifelse(exists(var_name),
paste(var_name, "_vct", sep = ""),
var_name)
and then
assign(var_name, 1, envir = .GlobalEnv)
Cheers,
Tiago
Em sex., 11 de dez. de 2020 ?s 15:20, Matt Denwood <md at sund.ku.dk>
escreveu:
On 11 Dec 2020, at 18:32, Tiago Olivoto <tiagoolivoto at gmail.com>
Hi everyone,
This can be a very simple question, but I really have the following
CRAN Policies says that 'Packages should not modify the global
(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
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]]