Closed adokter closed 2 years ago
The docker run
command in mount_docker_container
expects special characters and spaces to have a leading escape, i.e. this correctly mounts the container:
mount_docker_container("~/Dropbox/Eleonora\\'s\\ falcon")
however the normalize_Path
function does not expect added escapes, therefore I get a warning when passing this path string
> normalizePath("~/Dropbox/Eleonora\\'s\\ falcon")
[1] "/Users/amd427/Dropbox/Eleonora\\'s\\ falcon"
Warning message:
In normalizePath("~/Dropbox/Eleonora\\'s\\ falcon") :
path[1]="/Users/amd427/Dropbox/Eleonora\'s\ falcon": No such file or directory
Solution is therefore on Mac/Linux to
1) apply normalizePath first on path without escape characters.
2) to the output of 1) add leading \\
to all special characters and spaces (find out how)
Likely different solution needed on Windows
On Mac this seems to work, but only when the space is at the end of the path:
library(stringr)
mydir="~/Dropbox/Eleonora's falcon"
escape=function(string) {
str_replace_all(string, "(\\W)", "\\\\\\1")
}
paste(dirname(mydir),"/",escape(basename(mydir)),sep="")
[1] "/Users/amd427/Dropbox/Eleonora\\'s\\ falcon"
Correction: does not work, this also incorrectly escapes dots (.)
@stijnvanhoey maybe you know this from the top of your head:
I need a function that escapes the white space and special characters in a path, exactly as you would need in a shell
On Mac/Linux the path string ~/Dropbox/Eleonora's falcon/dir with whitespace/
should be translated into /Users/adriaan/Eleonora\\'s\\ falcon/dir\\ with\\ whitespace/
(need double backslashes in the string, in order to have a real backslash when I execute it with a system()
command).
On Windows (I think) c:/Dropbox/Eleonora's falcon/dir with whitespace/
should be translated into
"c:\Dropbox\Eleonora 's falcon\dir with whitespace"
(so with explicit quotes " in the string).
I've checked functionality of normalizePath
and shQuote
but can't get the escaping quite right. I'm also unsure which characters need escaping and which not, which is a hurdle to programming something myself.
This seems promising:
system(command="ls",input="/Users/amd427/Dropbox/Eleonora's falcon")
Correctly lists the directory contents without the need to escape anything
Update: doesn't seem to work when the call consists of multiple elements, like docker run ...
Just a guess: Would using 'file.path' to create the path name not properly parse this?
No unfortunately not - to interact with the Docker daemon I have to parse a path via a system()
call in R, as in
result <- system(
paste("docker run -v ",
"CORRECTLY_ESCAPED_PATH_GOES_HERE",
":/data -d --name vol2bird adokter/vol2bird sleep infinity",
sep = ""),ignore.stdout = TRUE)
file.path
doesn't add the escapes that you need in a shell that is opened by the system()
command ...
Closed by PR #174
This issue persists when using a local installation
Docker dependent functions (
read_pvolfile
for NEXRAD,nexrad_to_odim
,calculate_profile
) give an error when the file path contains a space