Unable to install R package in python (Jupyter notebook)? -


i trying install r package on python 3x in jupyter notebook.

i understand have pip install rpy2 , has been successful

this works fine when call built-in function in r such ccf or other easy issues.

# call function r import os os.environ['r_user'] = 'd:\anaconda3\lib\site-packages\rpy2' import rpy2.robjects robjects rpy2.robjects import pandas2ri pandas2ri.activate() 

however, if want install package such dirichletreg or vars, not easy there might more packages required downloaded.

i indeed followed link described in

r, python: install packages on rpy2

from rpy2.robjects.packages import importr utils = importr('utils') utils.install_packages('dirichletreg') 

but received following runtimeerror

--------------------------------------------------------------------------- rruntimeerror                             traceback (most recent call last) <ipython-input-16-32acf37e1ef9> in <module>()       1 rpy2.robjects.packages import importr       2 utils = importr('utils') ----> 3 utils.install_packages('dirichletreg')  d:\anaconda3\lib\site-packages\rpy2\robjects\functions.py in __call__(self, *args, **kwargs)     176                 v = kwargs.pop(k)     177                 kwargs[r_k] = v --> 178         return super(signaturetranslatedfunction, self).__call__(*args, **kwargs)     179      180 pattern_link = re.compile(r'\\link\{(.+?)\}')  d:\anaconda3\lib\site-packages\rpy2\robjects\functions.py in __call__(self, *args, **kwargs)     104         k, v in kwargs.items():     105             new_kwargs[k] = conversion.py2ri(v) --> 106         res = super(function, self).__call__(*new_args, **new_kwargs)     107         res = conversion.ri2ro(res)     108         return res  rruntimeerror: error in (function (pkgs, lib, repos = getoption("repos"), contriburl = contrib.url(repos,  :  py2/r/win-library/3.3'\anaconda3\lib\site-packages 

did found difficulty earlier?

jupyter notebook users (windows)

1) seems have been gone through r library not in same directory in python library

2) seems packages need installed in r first

to solve requires 2 major steps 1 in r , other in python jupyter notebook

step1: go r (rstudio)

code:

install.packages('dirichletreg', dep = true) 

this show

package ‘httpuv’ unpacked , md5 sums checked package ‘xtable’ unpacked , md5 sums checked package ‘sourcetools’ unpacked , md5 sums checked package ‘htmlwidgets’ unpacked , md5 sums checked package ‘shiny’ unpacked , md5 sums checked package ‘misctools’ unpacked , md5 sums checked package ‘rgl’ unpacked , md5 sums checked package ‘maxlik’ unpacked , md5 sums checked package ‘dirichletreg’ unpacked , md5 sums checked 

then load package in r

> loadnamespace('dirichletreg') 

it give output as:

<environment: namespace:dirichletreg> 

double check directory coding in r:

r.home() 

check output as

"c:/progra~1/r/r-33~1.3" 

trick!!!

this not place r downloading packages to. can see downloading coding in r:

.libpaths() 

say outcome xyz (copy this)

step 2: go jupyter notebook

check current r directory (i assume have rpy2 installed)

import rpy2 import os os.environ['r_user'] = 'd:\anaconda3\lib\site-packages\rpy2' rpy2.robjects.packages import importr base = importr('base') print(base.r_home()) 

the output be

"c:/program files/r/r-3.3.3" 

hence not match r library directory packages in xyz

hence import or install new package required to

dirichletreg = importr("dirichletreg", lib_loc = "xyz") 

this usaually work work me others

mi = importr("mi", lib_loc = "xyz") ggplot2 = importr("ggplot2", lib_loc = "xyz") 

but did not work dirichletreg gave me error

rruntimeerror: error in loadnamespace(name) : there no package called 'ggplot2' 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -