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.

2
  • 3
    It should be prep_data <- function(filepath, Year_First, Year_Last) with filepath unquoted. But I don't even see how that works without error Commented Oct 21, 2015 at 1:23
  • Thanks @RichardScriven. Commented Oct 21, 2015 at 1:29

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.