Search code examples
rdirectory

How to create multiples directories fom a vector?


I would like to create multiples directories from a vector.

I have this vector:

vector <- c(1, 2, 3) 

And I have tried this:

dir.create(c("A/B/C/", vector)) 

But I didn't get the expected directories:

  • A/B/C/1

  • A/B/C/2

  • A/B/C/3

How can I do it?


Solution

  • We can use paste and use a loop sapply as the ?dir.create documentation says

    path - a character vector containing a single path name

    sapply(paste0("A/B/C/", vector), dir.create) 
    

    data

    vector = c(1, 2, 3)