Access to data in different folders in the working directory in r

So, I installed my working directory, a folder called "Ril_1".

    setwd("~/Dropbox/Ril_1/")

There are two .R script files in this โ€œRil_1โ€ folder, another folder named โ€œScoreโ€ and another folder named โ€œSetupโ€. There are 21 TXT files in the โ€œScoreโ€ and โ€œSetupโ€ folders, which I would like to display as a list of 21 data frames, each .txt file is a data frame.

To do this, I installed the working directory three times ...

    setwd("~/Dropbox/Ril_1/")
    setwd("~/Dropbox/Ril_1/Score")
    #read in .txt files from "Score" file
    setwd("~/Dropbox/Ril_1/Setup") 
    #now read in .txt files from "Setup" file 

Is there a way to set the working directory to the "Ril_1" folder, and then read the data in the "Assessment" and "Settings" folders (listing each of them as a list of 21 data frames), as well as two .R script files?

Thank you in advance!

+3
source share
1

.

setwd("~/Dropbox/Ril_1/")

# Find the filenames in the two subdirectories
score.files <- dir("Score/", pattern="txt")
setup.files <- dir("Setup/", pattern="txt")

# Go through the score files and put them in a list 
scores <- sapply(score.files, function(f)
      {
      res <- read.table(paste0("Score/", f))
      res
      }, simplify=F)

# Go through the setup files and do the same
setup <- sapply(setup.files, function(f)
      {
      res <- read.table(paste0("Setup/", f))
      res
      }, simplify=F) 

[[]], :

scores[[3]]
+5

All Articles