How can I determine the current directory name in R?

后端 未结 2 1993
庸人自扰
庸人自扰 2021-01-07 19:03

The only solution I\'ve encountered is to use regular expressions and recursively replace the first directory until you get a word with no slashes.

gsub(\"/\         


        
相关标签:
2条回答
  • 2021-01-07 19:28

    If you didn't know basename (and I didn't), you could have used this:

    tail(strsplit(getwd(), "/")[[1]], 1)
    
    0 讨论(0)
  • 2021-01-07 19:33

    Your example code doesn't work for me, but you're probably looking for either basename or dirname:

    > getwd()
    [1] "C:/cvswork/data"
    > basename(getwd())
    [1] "data"
    > dirname(getwd())
    [1] "C:/cvswork"
    
    0 讨论(0)
提交回复
热议问题