Why does creating multiple directories in R using file.create cause invalid 'path' argument in Windows

Viewed 450

I have this simple example how I want to create multiple folders from a character vector in R:

folder <- c("test","names","for","rep","example")
list_of_paths <- paste("C:/Users/admin/Desktop/TEST123/",folder, sep="")
dir.create(list_of_paths)

It results in an error, which I could not resolve, saying Error in dir.create(list_of_paths) : invalid 'path' argument

However when I use a single string like

dir.create("C:/Users/admin/Desktop/TEST123/test")

it works. I would appreciate if someone could point me to the right direction here or show me the reason for the error. Thank you and have a good evening,

Konrad

1 Answers

According to ?dir.create

path - a character vector containing a single path name.

So, we may need to loop

sapply(list_of_paths, dir.create)
Related