How do I install Rscript in a Python template?

Just trying to run R with python

import subprocess


r_script = """
plot(1:10)
"""

with open('script.R', 'w') as file:
    file.write(r_script)


subprocess.run(['Rscript', 'script.R'])

FileNotFoundError: [Errno 2] No such file or directory: 'Rscript'

Welcome to the community @lamIronMan !

Go to your replit.nix file, you will see the deps session, add two lines:

deps = [
    pkgs.R #this one
    pkgs.python310Full
    pkgs.replitPackages.prybar-python310
    pkgs.replitPackages.stderred
    pkgs.rWrapper #and this one
  ];

After that go to your shell and use the command which R.

After that use the command which Rscript

It will bring you the full path of the Rscript, something like this:

/nix/store/cz3rd3k8cgwksj3nm1ms5l8cqlda2dvv-R-4.2.1/bin/Rscript

After that just change your code to include the full path:

import subprocess

r_script = """
plot(1:10)
"""

with open('script.R', 'w') as file:
    file.write(r_script)

subprocess.run(['/nix/store/cz3rd3k8cgwksj3nm1ms5l8cqlda2dvv-R-4.2.1/bin/Rscript', 'script.R'])