

Sapply(paste0("file", 1:100, ".txt"), file.create)Ĭopying a file can be done using py.įile.copy("source_file.txt", "destination_folder") For example, the one-liner below will create 100 empty text files: With this in mind, creating lots of files quickly is made easy. Similarly, creating a blank file can be done with file.create. If you don’t write out the full path of this new directory, it will get created into whatever the current working directory is i.e. You just need to replace “new_folder” with whatever name you choose. To change this directory, you can use the aptly named setwd function.Ī new folder, or directory, can be created in R using the dir.create function, like this:

In R, you can figure this out with the getwd function. The working directory is the folder that any files you create or refer to without explicitly spelling out the full path fall within. How to get and change the current working directoryīefore working with files, it’s usually a good idea to first know what directory you’re working in. In this post we’re going to talk about using R to create, delete, move, and obtain information on files. Though Python is usually thought of over R for doing system administration tasks, R is actually quite useful in this regard.
