Programmatically load files

前端 未结 2 829
终归单人心
终归单人心 2021-01-16 11:11

When I want to load a file into R, what would be a way to do so programmatically (or semi programmatically) instead of just manually copy paste the path and switch \\<

相关标签:
2条回答
  • 2021-01-16 12:01

    normalizepath maybe what you are looking for:

    > normalizePath(c(R.home(), tempdir()))
    [1] "C:\\Program Files\\R\\R-3.1.0"                    
    [2] "C:\\Users\\john\\AppData\\Local\\Temp\\RtmpysKuFi"
    > normalizePath(c(R.home(), tempdir()), winslash = '/')
    [1] "C:/Program Files/R/R-3.1.0"                 
    [2] "C:/Users/john/AppData/Local/Temp/RtmpysKuFi"
    

    Use readClipboard if you are on windows and have problems copying and pasting filepaths. For example I copy a file path from a windows folder so it is on the clip board then I can use:

    > readClipboard()
    [1] "C:\\Users\\john\\AppData\\Local\\Temp"
    

    You can then use `normalizePath to correct the windows flavour of paths.

    0 讨论(0)
  • 2021-01-16 12:01

    Perhaps use choose.files() to pick the file followed by normalizePath() if you want to convert its path name to R's forward slashes.

    0 讨论(0)
提交回复
热议问题