Error in R with list2env function

Asked

Viewed 80 times

2

I try to convert my list (which contains 12 dataframes and approx. 20,000 lines each) into separate dataframes:

list2env(mylist,envir=.GlobalEnv)

but, the following error message appears:

names(x) must be a character vector of the same length as x

What can be and what to do?

  • 3

    It seems that mylist does not have the attribute names. What attributes(mylist) gives? A solution may be names(mylist) <- paste("membro", seq_along(mylist), sep = ".").

  • It worked! Thank you for your attention.

  • 1

    It’s just that without names like R can create objects in .GlobalEnv or any other Nvironment? They are called what?

1 answer

3


As noted by @Ruibarradas, the list should be named that can be transformed into environment.

Reproducing the error:

mylist <- list(1, 2, "a")
list2env(mylist,envir=.GlobalEnv)
# Error in list2env(mylist, envir = .GlobalEnv) : 
#   names(x) deve ser um vetor de caracter de mesmo comprimento que x

Applying the solution we have

names(mylist) <- paste("membro", seq_along(mylist), sep = ".")
ls()
# [1] "mylist"
list2env(mylist,envir=.GlobalEnv)
# <environment: R_GlobalEnv>
ls()
# [1] "membro.1" "membro.2" "membro.3" "mylist" 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.