DS4PS / cpp-528-fall-2020

Course shell for CPP 528 Foundations of Data Science III - Project Management
http://ds4ps.org/cpp-528-fall-2020/
1 stars 1 forks source link

Lab-02: Import Data Error #18

Open hos1995 opened 3 years ago

hos1995 commented 3 years ago

I'm trying to create a new RMD file so I can make the functions for the lab and I get an error whenever I run the following:

library(dplyr)
library(readr)

dat <- read.csv( "../data/raw/ltdb-data-dictionary.csv", stringsAsFactors=F )

The error I get says:

Error in file(file, "rt") : cannot open the connection
3. file(file, "rt")
2. read.table(file = file, header = header, sep = sep, quote = quote, dec = dec, fill = fill, comment.char = comment.char, ...)
1. read.csv("../data/raw/ltdb-data-dictionary.csv", stringsAsFactors = F)

Am I missing a step to connect to the where the csv file is? I determined the file-path from the project and yet it's still saying it's not connected.

cenuno commented 3 years ago

@hos1995 You are correct that you are not pointing to the right relative path.

If you use read.csv(here::here('data/raw/ltdb-data-dictionary.csv'), stringsAsFactors=F), this error should be resolved. When you use the here::here() function, you can always assume your file path starts at the root of your project folder (i.e. where ever your .Rproj file lives).

This is useful whenever analysis files are located in a different directory from where the data lives. For more context checkout WK02's lecture videos on this function and the concept of portability.

hos1995 commented 3 years ago

@hos1995 You are correct that you are not pointing to the right relative path.

If you use read.csv(here::here('data/raw/ltdb-data-dictionary.csv'), stringsAsFactors=F), this error should be resolved because you can always assume your file path starts at the root of your project folder (i.e. where ever your .Rproj file lives).

Thank you! That worked great!