how to use effectively the R keras (and other R packages using python in its background) on google colab's notebook with python kernel?

Viewed 96

This is partially related to an already closed question about keras package and R in google colab. But I have some specific doubts in such a workflow...

1 .It is known we have how to use R in google colab. And the use of the google colab's GPU and TPU are indeed interesting.

  1. And although the documentations says we need to run install_keras() in R if we want to use GPU on keras, at google colab it works without this setting. Neither python installation is required.

  2. But deep learning processes are time consuming... running all the code in just one notebook have some limitations... Splitting into several ones, saving and sharing the resultant object to re-use in the next notebook can be interesting.

  3. We can think the above is more desirable specially because the environment is ephemeral. And the solution would be mounting the google drive to be able to use its data, and save some partial outputs on it. But mounting google drive appears to be restricted to python notebooks... yes, we have discussions proposing solutions as here and here but I was not able to implement them...

So I am really curious how the R keras users (and other R users) deal with such an issue when using google colab?

If we keep in this idea of a workflow using more than one notebook, some possible related questions is this one (without answer)


So, I have tried to another alternative: using the python notebook and run R in specific cells inside it using rpy2 like indicated here and other discussions I mentioned before... Yes, one can ask why not coding on Python... Ignoring it and still keeping R...

But happens that R's keras is an api for python keras, and need python to run... But I do not why, when I try to run any keras function, even a simple

%%R
imdb<-dataset_imdb()

I get:

R[write to console]: Error: Error 1 occurred creating conda environment /root/.local/share/r-miniconda/envs/r-reticulate

  • I also see one saying Rkerkel does not see the colab's python like here, but I know it is not true, because R'keras works in the Rkernel, and if I run the same py_config, I am able to see the python versions...
  • But the point is... why in this python notebook, using rpy2, we cannot verify the Python...?
  • If we run the notebook with R Kernel, the all package requiring python works well without any intervention... that's strange...
  • I see discussions of how to install conda like here. But I believe this should not be the way... Maybe is related to rpy2...

I have tried some alternatives to check the existence of python versions inside the R cells (called with %%R), and I believe the R called in this sense are not able to see python...

%%R
library(reticulate)
py_config()

It returns the same

R[write to console]: Error: Error 1 occurred creating conda environment /root/.local/share/r-miniconda/envs/r-reticulate

Error: Error 1 occurred creating conda environment /root/.local/share/r-miniconda/envs/r-reticulate


So, my major question: how to use effectively the R keras (and other R packages using python in its background) inside google colab's notebook with python kernel?

What I am missing here with rpy2?

0 Answers
Related