Creating an automatic folder's path

I would like to make the path to the input files automated, asking the user to enter only the last part of the path (year) as the root of the path is always the same (path_root), I have tried with the following instructions:

#set the input path's root
path_root= "W:\GRAN_PARADISO\Sentinel2\T32TLR\Level2"

#taking input year from user with showing the message 
year <- readline(prompt="Enter the scenes' acquisition year to pre-process: ")

#build the entire path
repo <- file.path(path_root, year)

#set working directory
setwd(repo)

but it returns the following error:

Error in file.path(path_root, year) : object "path_root" not found

Does the first line of code run ? I would think it wouldnt because the \ are not escaped ...

path_root <- 'W:\\GRAN_PARADISO\\Sentinel2\\T32TLR\\Level2'

# better in my opinion
path_root <- file.path("W:",
                       "GRAN_PARADISO",
                       "Sentinel2",
                       "T32TLR",
                       "Level2"
                       )
1 Like

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.