1

I am trying to enter a file path into a function where part of the function reads data from .csv files from a folder specified in the function.

This part of the script:

prep_data <- function("filepath", Year_First, Year_Last)  {
...
FileName <- paste0(filepath,"/details", Year_Index, "moredetails", Year_Index, ".csv")
Tbl_Year <- read.csv(FileName)

Where

prep_data("/users/me/etc", 1980, 2014)

Is giving me this error:

In file(file, "rt") :
cannot open file 'filepath/details1980moredetails1980.csv': No such file or directory

My desired file path would be:

/users/me/etc/details1980moredetails1980.csv

This line is in a for loop that is reading .csv files for the range of specified years.

Limon Monte
  • 52,539
  • 45
  • 182
  • 213
Bret Shandro
  • 61
  • 1
  • 9

1 Answers1

1
read.csv(paste0(getwd(),'/details/, Year_Index, 'moredetails', Year_Index, '.csv'),header=TRUE,sep=',',FactorAsString=TRUE)

Suggest try getwd() for filepath if your files saved in directory.