filepath

Published onesixx on

> myPath = file.path("~/myfolder" ,"myfilename.data")
> myPath
[1] "~/myfolder/myfilename.data"

> path.expand(myPath)
[1] "/Users/onesixx/myfolder/myfilename.data"

> dirname(myPath)
[1] "/Users/onesixx/myfolder"

> basename(myPath)
[1] "myfilename.data"
> list.files(path='.')
[1] "ess_dev.Rproj"  "QuickTip"       "Test_File1.csv"

> list.files(path=getwd(), full.names=T)
[1] "/Users/onesixx/sixxDoc/RCODE/ess_dev/ess_dev.Rproj" 
[2] "/Users/onesixx/sixxDoc/RCODE/ess_dev/QuickTip"      
[3] "/Users/onesixx/sixxDoc/RCODE/ess_dev/Test_File1.csv"

> list.files(path=getwd(), all.files=T, recursive=F)
 [1] "."              ".."             ".DS_Store"      ".RData"        
 [5] ".Rhistory"      ".Rprofile"      ".Rproj.user"    "ess_dev.Rproj" 
 [9] "QuickTip"       "Test_File1.csv"

> list.files(path=getwd(), no..=T)
[1] "ess_dev.Rproj"  "QuickTip"       "Test_File1.csv"

> list.files(path=getwd(), pattern = ".csv$")
[1] "Test_File1.csv"

> list.dirs(path=getwd())
 [1] "/Users/onesixx/sixxDoc/RCODE/ess_dev"                                       
 [2] "/Users/onesixx/sixxDoc/RCODE/ess_dev/.Rproj.user"                           
 [3] "/Users/onesixx/sixxDoc/RCODE/ess_dev/.Rproj.user/859D209"                   
 .....                         
[27] "/Users/onesixx/sixxDoc/RCODE/ess_dev/QuickTip/www/images" 

File Manipulation

file.create(..., showWarnings = TRUE)
file.exists(...)
file.remove(...)
file.rename(from, to)
file.append(file1, file2)
file.copy(from, to, overwrite = recursive, recursive = FALSE,
          copy.mode = TRUE, copy.date = FALSE)
file.symlink(from, to)
file.link(from, to)
> file.info("~/df.rds")
         size isdir mode               mtime               ctime               atime uid gid   uname grname
~/df.rds  240 FALSE  644 2020-03-22 20:55:45 2020-03-22 20:55:45 2020-03-23 01:10:44 501  20 onesixx  staff
Categories: R Basic

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x