Skip to content
Advertisement

python in Rmarkdown using reticulate cannot read packages

I am using R on a MacBook. I have an Rmarkdown document and I’m trying to use reticulate in order to use python within R.

First I download the libraries:

JavaScript

Next I look at an R chunk and figure out my working directory. Then I write mtcars to my desktop.

JavaScript

Then I try to use python instead to read in that csv that I just wrote to my desktop.

JavaScript

But I get this error:

JavaScript

So I went to this R documentation website and discovered that with python you have to import packages differently. So I went to terminal and then I typed in

JavaScript

It seemed to download OK? But when I return to my Rmarkdown document I can’t seem to get the python code to run and read in the csv. I still get the same error message.

I also saw a similar question on this SO post but I’m certain that my RStudio version is newer than the version in this question, so I don’t the answer hits on the same error exactly.

Advertisement

Answer

An option is to create a virtualenv, install the package and then specify the virtual env to be used

JavaScript

In the rmarkdown, we can use

JavaScript

-output

enter image description here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement