Problems with file paths in R? Open your data with the “here” package

I like to save my rawdata in csv format (from excel, Stata or other sources), which makes the access easy as well as it is a durable file format that most likely will be relatively unaffected by new versions of software and thus is a good file format for archiving your data.

Make sure that the csv actually is comma seperated, not tab seperated or semicolon seperated, cause R doesn´t really like those. If you happen to create semicolon seperated csv files from Excel, you probably need to change your region settings, as region and the csv format are linked in Excel, which is weird but true.

In R, to avoid problems with file paths when working on different computers, or switching from PC to Mac, use the “here” package. It is very simple and easy to use, but you need to make sure that you have organized your R/R studio project in the same folder hierarchy as your csv file.


Then, open your csv in R using the code below. Notice that you do not need to specify the file path, if you have activated the here package before.

# Get the data
yourdata <- read.csv(file="mycsvfile.csv") 

Now your dataframe should appear in your environment, well done!