A way to rename the objects of a environment
may be as follows.
renameObject <- function(old, new, envir){
for(i in seq_along(old)){
assign(new[[i]], get(old[[i]], envir = envir), envir = envir)
rm(list = old[[i]], envir = envir)
}
invisible(NULL)
}
ls()
#[1] "renameObject"
ola <- data.frame(x = 1)
tudo_bem_com <- data.frame(x = 2)
voce <- data.frame(x = 3)
ls()
#[1] "ola" "renameObject" "tudo_bem_com" "voce"
renameObject(c("ola", "tudo_bem_com", "voce"), paste0("dataset", 1:3), .GlobalEnv)
ls()
#[1] "dataset1" "dataset2" "dataset3" "renameObject"
dataset1
# x
#1 1