create a directory in r

To create a new directory in R, you can use the dir.create() function. This function takes one argument, which is the path of the directory that you want to create. Here's an example:

main.r
# create a new directory called "mydir"
dir.create("mydir")
60 chars
3 lines

You can also create a directory with multiple levels by specifying a path that includes subdirectories. For example:

main.r
# create a new directory called "mydir" inside the "data" directory
dir.create("data/mydir")
93 chars
3 lines

If the directory already exists, dir.create() will return FALSE, indicating that it was not created. To avoid this, you can use the exist.ok parameter, which will not throw an error in case the directory already exists:

main.r
# don't throw an error if "mydir" already exists
dir.create("mydir", exist.ok = TRUE)
86 chars
3 lines

That's it! You now know how to create a directory in R.

gistlibby LogSnag