Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding absolute path for file on network drive

Tags:

path

r

knitr

I am having some trouble knitting a markdown file which is sitting on a network drive. I am using rmarkdown::render() to knit the file. I have tracked the problem down to the file_path_as_absolute() function.

I have a markdown file, foo.Rmd, in my working directory.

> list.files()
 [1] "$RECYCLE.BIN"                               "2014-11-04-popular-wagers-distribution.pdf"
 [3] "db-connection.R"                            "desktop.ini"                               
 [5] "figure"                                     "foo.md"                                    
 [7] "foo.Rmd"                                    "game-popularity.R"                         
 [9] "My Data Sources"                            "player-data-game-monitoring.tsv"           
[11] "player-linking.R"                           "player-pca.R"                              
[13] "query-1.sql"                                "query-2.sql"                               
[15] "R"                                          "report-test-2.Rmd"                         
[17] "report-test.md"                             "report-test.Rmd"                           
[19] "report-test.xxx"                            "SQL Server Management Studio"              
[21] "test.md"                                    "test.R"                                    
[23] "test.Rmd"                                   "Thumbs.db" 

I can find the absolute path:

> normalizePath("foo.Rmd")
[1] "\\\\dernetapp02\\h$\\users\\AndrewCo\\myCitrixFiles\\Documents\\foo.Rmd"
Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
  path[1]="foo.Rmd": Access is denied

This works although it generates a warning. I am not sure why I get this warning because I certainly do have both read and write access to the file.

But calling file_path_as_absolute(), which is just a wrapper for normalizePath(), turns that warning into an error.

> tools::file_path_as_absolute(input)
Error in normalizePath(path.expand(path), winslash, mustWork) : 
  path[1]="foo.Rmd": Access is denied

I am pretty sure that the problem relates to the fact that the file is on a network drive because I do not encounter this issue when I do the same thing with a file on my local drive. However, as mentioned above, I do have read/write access to this file.

Does anybody have any ideas for the source of this problem? And, more importantly, a possible solution?

Based on a suggestion (below) I tried mapping to a network drive:

> system("net use s: \\\\dernetapp02\\h$")

This seemed promising but ended up with the same results:

> normalizePath("s:\\users\\AndrewCo\\myCitrixFiles\\Documents\\foo.Rmd")
[1] "s:\\users\\AndrewCo\\myCitrixFiles\\Documents\\foo.Rmd"
Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
  path[1]="s:\users\AndrewCo\myCitrixFiles\Documents\foo.Rmd": Access is denied

Thanks!

Best regards, Andrew.

like image 410
datawookie Avatar asked Dec 05 '14 14:12

datawookie


1 Answers

Same problem here. I ended moving the project in a local folder and copying the produced file with the command file.copy.

It is a generic solution and if someone find one better, I am interested in.

like image 147
YCR Avatar answered Oct 14 '22 21:10

YCR