Owen
Owen

Reputation: 466

Jupyter notebooks: how to run a terminal command with a python variable input

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?

Upvotes: 0

Views: 920

Answers (1)

Owen
Owen

Reputation: 466

Solution: Enclose variables in braces:

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

or prefix by a $ sign:

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

Upvotes: 2

Related Questions