A simple solution to ditch the question "what's the path of my data" when importing data to R

Load packages

library(tidyverse)

Motivation

Importing data to R can cause headaches for newbies. For some, the concept of relative and absolute paths is new. That’s why I compiled here some recommendations on how to important data into R and on how to ditch the “what’s my path” problem.

Approach 1: Start an RStudio project

That’s an approach I generally recommend.

  1. Start an RStudio project.
  2. Put your code files and your data files in this very folder.
  3. Import the data without specifying any paths, eg., d <- read.csv("mydata.csv)

Approach 2: Import from an online source

That’s also convenient – as long as someone has put the data online.

  1. Identify the URL of your data set, and copy it.
  2. Open up an R/Rmd script file and paste the URL to your import function, e.g,. d <- read.csv("https://vincentarelbundock.github.io/Rdatasets/csv/reshape2/tips.csv")

Approach 3: Learn what a path means

  1. Identify the location (path) of your data file on your computer.
  2. Copy it to the clipboard (depends on your operating system).
  3. Paste it into your import function, e.g, `d <- read.csv(“/Users/sebastiansaueruser/datasets/tips.csv”)

Example time – dataset tips

tips <- read.csv("https://vincentarelbundock.github.io/Rdatasets/csv/reshape2/tips.csv")