1

For context: My goal is to create a graphic interface so that the user can run a program that I have been developing in R. The interface is done using the Tkinter module from python (version 3.3). Right now I am trying to make it work in Windows.

I believe I have successfully called the R interpreter using python to run my R file (run.R). In this file I call the R package 'seqinr'. However when I call the R interpreter from python I obtain this:

I run this:

os.system('C:/"Program Files"/R/R-3.6.1/bin/Rscript run.R')

and I obtain this:

Error in library(seqinr) : there is no package called 'seqinr'
Calls: source -> withVisible -> eval -> eval -> library
Execution halted

However, when I run the 'C:/"Program Files"/R/R-3.6.1/bin/Rscript run.R' command in the Command Prompt, it works perfectly and I have no problems. I also checked where my package is installed and it's in the default directory that R uses to install all the packages. I also do not have any other R versions installed in my machine.

I have no clue what is happening now, so I would appreciate any help.

Thank you!

  • 1
    [Possible duplicate of](https://stackoverflow.com/q/50747617/4752675) – G5W Nov 25 '19 at 16:38
  • Had a look at this? This is my go to module for R in python https://rpy2.readthedocs.io/en/version_2.8.x/introduction.html – Jkind9 Nov 25 '19 at 16:38

1 Answers1

0

Although probably not satisfactory, I'd recommend changing your "run.R" file to include the following lines:

if (!("seqinr" %in% installed.packages())) {
    install.packages('seqinr', repos = "https://cloud.r-project.org")
}
library(seqinr)

This will install the package if it isn't available to wherever R is looking for packages when being called from Python. Additionally, you could include print(rownames(installed.packages())) in your "run.R" file to see what packages are currently available to your R installation at run time when calling from Python. Inclusion of the line print(.libPaths()) will tell you where R is looking for installed packages at run time as well.

user387832
  • 503
  • 3
  • 8