2

I have a list of dataframes that I have created using

list_dataframes = list(dataframe_1, dataframe_2...)

And now I wonder how to unlist this list.

I have searched for it and found this solution:

list2env(list_dataframes ,.GlobalEnv)

in this old question: Unlist a list of dataframes

However, when using that solution, the following error arises:

Error in list2env(list_dataframes, .GlobalEnv) : 
  names(x) must be a character vector of the same length as x

Any idea why it's happening?

Thanks!

AlejandroDGR
  • 178
  • 1
  • 10
  • 2
    It should be a named list i.e. list(dataframe_1 = dataframe_1, ...` – akrun May 23 '22 at 15:19
  • Why exactly do you want to unlist your list? It's normally much easier to work with data in a list rather than clobber your global environment with a bunch of variables. You might just be making things more difficult for yourself. – MrFlick May 23 '22 at 15:23
  • 1
    Absolutely correct @akrun. Thanks a lot! – AlejandroDGR May 23 '22 at 15:25
  • It's only a matter of convinience for me @MrFlick – AlejandroDGR May 23 '22 at 15:26
  • 1
    Likely duplicate: [Error in list2env(list, envir = .GlobalEnv) : names(x) must be a character vector of the same length as x](https://stackoverflow.com/q/63906806/13095326) – Ian Campbell May 23 '22 at 15:30

1 Answers1

2

The error is a result of passing a list without names

list2env(list(1, 2, 3), .GlobalEnv)

Error in list2env(list(1, 2, 3), .GlobalEnv) : names(x) must be a character vector of the same length as x

list2env(list(a= 1, b = 2, c = 3), .GlobalEnv)
<environment: R_GlobalEnv>
user438383
  • 5,716
  • 8
  • 28
  • 43
akrun
  • 874,273
  • 37
  • 540
  • 662