Trouble Importing Datasets into R

Having trouble importing datasets to my program. Beginner programmer here, with little experience in the field. I've tried importing the datasets manually using file.choose() function and also setting my working directory to my specific data function, but keep getting the same error. I've also downloaded tidyverse and readr prior to running the program so that doesn't seem to be the problem either.

My console just ends up saying:

Error: 'data/StateData.csv' does not exist in current working directory

And

Error in import("data/StateData.xlsx") : No such file

likely means that StateData.csv is in a different directory than expected. The recommended way to simplify locating files is using the {here} package. Install with

install.packages("here")

First look at the files pane in RStudio (if you're not using RStudio, come back for further direction)

to confirm that you have a data directory in your current working directory. Then click into it to confirm that you have StateData.csv saved there. Then

suppressPackageStartupMessages({
  library(here)
  library(readr)
})

dat <- read_csv(here("data/StateData.csv"))
                

Followed your instructions. Thank you for your reply.

Error: '/Users/ahaddaudi/Desktop/data/data/StateData.csv' does not exist.

This is what I'm still getting.

  1. Does it exist? Check in a file manager application or from terminal.
  2. Check your working directory with getwd() from the console. The here call should be relative to there.

It exists, as I can import the data manually from the file tab (on a Mac) but for some reason the data itself is not able to be read through the commands:

(df <- read.csv("data/StateData.csv"))

Attached below is a screenshot of what my problem looks like.

There's a clue in the first error message . There's a repeated data/data/ that implies your earlier code set things up so that your later code should omit the data/ before the csv name.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.