I have used rpy2 to call R package successfully in python. However, I just install elasticnet today in R and I checked I can load the library in R without problem, also the package name folder elasticnet is in my directory.
I want to do the same call as other packages using importr
, but it keeps giving me error message:
Error in loadNamepace(name): there is no package called 'elasticnet'.
But I have go to that address and actually see the package, also in R I can see that package is installed. Anyone know how to solve this problem?
This is how I called other packages in python, for example the pls
package:
import rpy2
import rpy2.robjects as ro
from rpy2.robjects.packages import importr
utils = importr("utils")
d = {'print.me': 'print_dot_me', 'print_me': 'print_uscore_me'}
pls = importr('pls', robject_translations = d, lib_loc = "/Users/Viii/Anaconda3/envs/rstudio/lib/R/library")
But when I replace that with elasticnet
, it doesn't work.
And it gives me the error message saying
"RRuntimeWarning: 'package 'lars' was installed by an R version with different internals; it needs to be reinstalled for use with this R version'.
I also try to install glmnet
instead, it also gives me the error message
en = importr('glmnet', robject_translations = d, lib_loc = "/Users/Viii/Anaconda3/envs/rstudio/lib/R/library")
Traceback (most recent call last):
File , line 1, in en = importr('glmnet', robject_translations = d, lib_loc = "/Users/Viii/Anaconda3/envs/rstudio/lib/R/library")
File "C:\Users\Viii\Anaconda3\lib\site-packages\rpy2-2.9.4-py3.6-win-amd64.egg\rpy2\robjects\packages.py", line 453, in importr env = _get_namespace(rname)
RRuntimeError: Error in loadNamespace(name) : there is no package called 'glmnet'
The sessioninfo in R:
R version 3.5.0 (2018-04-23)
Platform: x86_64-conda_cos6-linux-gnu (64-bit)
Running under: Ubuntu 16.04.5 LTS
Matrix products: default
BLAS/LAPACK: /home/viii/anaconda3/envs/rstudio/lib/R lib/libRblas.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods [7] base
other attached packages:
[1] elasticnet_1.1.1 lars_1.2
loaded via a namespace (and not attached):
[1] compiler_3.5.0 tools_3.5.0 yaml_2.1.18