0

Im running an rscript from bash script using:

retval=`./rcode.r` 

In rcode print is called many times for debugging purpose. When retval is checked, it has values from all print statements.

How to return only a single value from a script? Is there any other command to use? What is the right way to return a value from r script to the caller(console/bash)?

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
sjd
  • 1,329
  • 4
  • 28
  • 48
  • 1
    https://stackoverflow.com/questions/1109017/how-do-you-print-to-stderr-in-r (you need to "print" diagnostics to `stderr` so your "single value" is the only thing on `stdout` and I think you want to use \`./rcode.r` or `$(./rcode.r)` vs the double-quoted thing you are using. – hrbrmstr Dec 04 '18 at 08:11
  • How does `retval="./rcode.r"` run anything in bash? Have some backticks gone missing because StackOverflow uses them to style code? Did you mean `retval="\`./rcode.r\`"` ? – Spacedman Dec 04 '18 at 08:54
  • Yes as SO uses `` for styleing i used double quotues. I am using backticks for execution. – sjd Dec 04 '18 at 09:31
  • @hrbrmstr Thanks. from the link i could see `write` can be used. also `message` seems better which by default redirects to `stderr`. A comprehensive answer is found in this link https://stackoverflow.com/questions/36699272/why-is-message-a-better-choice-than-print-in-r-for-writing-a-package – sjd Dec 04 '18 at 10:05

0 Answers0