I want to get the parent directory from a folder path.
say I have: "C:/Users/YS/2020 projects/APP/pect/PDC/src"
and I want to get: "C:/Users/YS/2020 projects/APP/pect/PDC"
#Get current directory
cpath = getwd()
#Remove last folder from path
dir <- strsplit(cpath,"/")
dir <- dir[[1]]
parent_dir <- dir[1:length(dir)-1]
#Return file path
file.path(parent_dir)
These are my environment variables:
and here is the output I get from the code:
[1] "C:" "Users" "YS" "2020 projects" "APP" "pect" "PDC"
I want it to return:
[1] "C:/Users/YS/2020 projects/APP/pect/PDC"
Why can't I pass a list of characters into file.path()?
I'm a little confused by how dir in my environment variables is listed as a character not a list or vector
I'm also a little confused by why strsplit returns a list with 1 value in it?