I am running this code in a R program, but In order to be able to use linux commands from the shell, I need to invoke sudo first. For instance, if I want to copy a file "cp file.tsv file_copy.txt" I have to write "sudo cp file.tsv file_copy.txt.Is it possible to use sudo in the code? How should I do that?
if (paste(dirname(inFileName), “/”, sep="") != OUTpath ) {
OS<- Sys.info()[“sysname”]
if (OS==“Windows”) {
copyCommand<- “copy”
} else {
copyCommand<- “cp”
}
paramsCopyFn<- sub(".tsv", "_copy.txt", paramsCopyFn, fixed=T)
cmd1<- paste(copyCommand, shQuote(inFileName), shQuote(paramsCopyFn) , sep=" ")
execSystemCmd(cmd1)
}
execSystemCmd<- function(cmd, OS=NULL) {
if (is.null(OS)) OS<- Sys.info()["sysname"]
if (OS=="Windows") {
shell(cmd, translate=TRUE)
} else {
system(cmd)
}