#Check if the folder "Data" exists in the current directory, if not creates it #Check if the file "raw data.csv" exists in the working directory , *, $ these are called metacharacters in regular expressions. If you want to learn more about regular expressions you can watch these two videos: Regular Expressions in general and Regular Expressions in R. If you’re wondering what are the symbols ^. List.files(pattern = "^Product(.*)xlsx$") #list files that start with the word "Product" followed by anything and ending with the word "xlsx": #list all files that contain the word "Product" If you get a very long list, you can filter the results using the pattern argument of the list.files() function #get the full name (path and file name) of each file #list of subfolders and files within the subfolders List.files (path = "C:/Folder/Subfolder1/Subfolder2") You might also want to create a list of all the files or folders in a directory Creating a list of files and folders in a directory Tip: If you are using RStudio you can use the shortcut Ctrl + Shift + H to browse to the desired directory. Setwd(paste0(getwd(), "/Statistical Analysis")) #Set the working directory to a subfolder within the current working directory For example, let’s say you want to set the working directory to a subfolder called “Statistical Analysis”: If you want to setup the working directory to a subfolder within your current working directory you don’t have to specify the whole path. Setwd("C:/Documents and Settings/Folder name") Therefore, the first thing you need to know is how to get and setup your working directory. ![]() Unless you specify it otherwise, all files will be read and saved into the working directory. In this post I’ll cover how to work with files and folders in R.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |