0

From my Jupyter/IPython notebook I need to run an R script from a terminal command, using a Python variable as input:

x = "Owen" 
! Rscript ./sayHello.R x

However, the variable x is not recognized (ie. Python namespace is not included). How can you address this?

Owen
  • 448
  • 3
  • 11
  • Duplicate of https://stackoverflow.com/questions/55416796/python-executing-a-terminal-command-from-jupyter-notebook , https://stackoverflow.com/questions/35497069/passing-ipython-variables-as-arguments-to-bash-commands – Owen Mar 30 '22 at 05:19
  • Admins, welcome to close this as a duplicate. I felt it was best to post the question as it uses different keywords so it was hard to find these duplicates. – Owen Mar 30 '22 at 05:20

1 Answers1

2

Solution: Enclose variables in braces:

x = "Owen" 
! Rscript ./sayHello.R {x}

or prefix by a $ sign:

x = "Owen"
! Rscript ./sayHello.R $x
Owen
  • 448
  • 3
  • 11