Run Unix Shell Commands in R

I am newbie to R. I am trying to run the below unix shell command from R studio. Do I need to download any appropriate unix shell for windows? Please Help

shell(paste('tr -d "|\t" < ', origFile, " > ", inputFile))

I end up getting the commands are not recognized. Below is the output

'tr' is not recognized as an internal or external command,
operable program or batch file.
Warning message:
In shell(paste("tr -d "|\t" < ", origFile, " > ", inputFile)) :
'tr -d "| " < C:/NPPES/2019_07/npidata_pfile_20050523-20190707.csv > C:/NPPES/2019_07/npidata_pfile_20050523-20190707_upd.csv' execution failed with error code 1

Hi, and welcome. Take a look at the system2 function in {base}


for the tools to apply available OS programs, including terminal commands.

If's preferable, however, to do the same operation in R when an equivalent is available. In your example, the stringr package combined with the magrittr package will work depending on the nature of your input file. Assuming origFile.csv with the offending string in a single column, you would first read it in as a dataframe, and then delete your string.

inputFile <- origFile %>% mutate(tab_column = str_replace(tab_column, "\\|\\t", "")

It's always helpful when posing a question to include a reproducible example, called a reprex. Thanks!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.