2

I have a .sh script with calls internally a R script.

This R Script use some directories that I print in my program.

My problem is that the output I am generating in my R script is used after its execution another time in the .sh script.

Example:

  1. Calls join_files.sh, we pass init_month / end_month
  2. Using this init and end month the R script joins all files between those months
  3. I want to get that directories that are being used by my R script, I print them in the R Script and using 'cat' command in R I can get them, but all extra information is being printed.

Is there a way to print directly in the shell using R script?

fiticida
  • 664
  • 1
  • 10
  • 24
  • 1
    Possible duplicate of [How do you print to stderr in R?](https://stackoverflow.com/questions/1109017/how-do-you-print-to-stderr-in-r) – divibisan Mar 04 '19 at 17:59

1 Answers1

2

You can suppressMessages that you dont want and only print the needed info. Example:

$ cat sample.sh
output=`Rscript sample.R`
echo $output

$ cat sample.R
suppressMessages(library(tidyverse))
i=100
print(i)

$ sh sample.sh
1 100
Sonny
  • 3,083
  • 1
  • 11
  • 19