Recently, I found the base::files
commands. Along with other commands like getwd
, write.lines
, file.show
, dir
, etc. there seem to be a number of R equivalents of bash functions.
I have also written some functions in R that streamline calls to ssh
and rsync
through system
.
for example:
rsync <- function(from, to){
system(paste('rsync -outi', from, to, sep = ' '), intern=TRUE)
}
But before I go to much further with this, I have a few questions:
rsync
example above? does R already have built in commands for common shell programs, if so, where can I find them?
There are some function like grep
that mimic shell progams. Search for them as you would any other function – the names are often the same.
if not, are there reasons to avoid writing my own functions?
No obvious problems.
is there a better alternative to the approach outlined in the rsync example above?
Looks good, but you need to be very careful about checking user input if things are passed to the shell.
would a collection of such functions warrant a package?
Absolutely. Go for it.
I started to go down that route with wrapping git functions for devtools, but eventually realised what I needed was:
bash <- function() system("bash")
with a bit of wrapping to make sure I ended up in the right directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With