Friday, 16 July 2021

How to pass integer arguments to R-script from python

i have the below posted R-code and i want to pass the parameter nfrom python code and display the results. that is, if i passed 4 then 16 must be printed out on the screen. please let me know how to pass argumnets to R-script from python

R-Code:

Square <- function(n) {
return(n^2)
}

Python-code:

command ='Rscript'
path2Func1Script ='/var/www/aw/Rcodes/func-1.R'
args = [3]
cmd = [command, path2Func1Script]

output = None
try:
    x = subprocess.call(cmd + args, shell=True)
    print("x: ", x)
except subprocess.CalledProcessError as e:
    output = e.output
    print("output: ", output)


from How to pass integer arguments to R-script from python

No comments:

Post a Comment