Closed PabRod closed 3 years ago
@wandadk, in future edits, please consider replacing:
system(paste0('command1', object1, 'command2', object2, ..., intern = TRUE, ignore.stderr = TRUE))
by the more readable:
systemf('command1 %s command2 %s', object1, object2)
The idea is that each %s
is a placeholder for each of the strings that are passed immediately afterwards.
# With paste0
system(paste0("tar -xvzf ", wvpCompressed, " -C ", wvpfolder), intern = TRUE, ignore.stderr = TRUE)
# With systemf (basic usage)
systemf("tar -xvzf %s -C %s", wvpCompressed, wvpfolder)
# It (optionally) accepts variable names
systemf("tar -xvzf %s -C %s", orig = wvpCompressed, dest = wvpfolder)
# intern and ignore.stderr are TRUE by default, but can be overridden
systemf("tar -xvzf %s -C %s", wvpCompressed, wvpfolder, intern = FALSE, ignore.stderr = FALSE)
Sorry for not having noticed this potential enhancement before. I will refactor the paste0
's we have already written in the next days.
Implemented in https://github.com/RETURN-project/makeDataCube/commit/178cb6e1fafbda2eb7e0d8fc24642eff01ec399e and tagged as v0.2.
@wandadk: this version includes some major changes that I could test only partially. In particular, I managed to correctly reproduce the full workflow from scratch and as a re-run.
In case something fails, I've tagged the non C-style version of this code as v0.1.
Problem
This project often passes strings to the function
system
. These strings represent shell commands. The commands are built by pasting together it's parts, for instance:These commands can (arguably) be a bit difficult to read.
Improvement
A neater way of building string commands is to use
sprintf
instead ofpaste0
.References