I am trying to improve my research by the combining of R and Python advantages. Reticulate package is a promising tool for this purpose. But something comes wrong...
devtools::install_github("rstudio/reticulate")
library(reticulate)
py_available()
[1] FALSE
py_config()
python: /usr/bin/python
libpython: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib
pythonhome: /System/Library/Frameworks/Python.framework/Versions/2.7:/System/Library/Frameworks/Python.framework/Versions/2.7
version: 2.7.10 (default, Oct 23 2015, 19:19:21) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]
numpy: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
numpy_version: 1.8.1
python versions found:
/usr/bin/python
/usr/local/bin/python
/usr/local/bin/python3
/Users/User/anaconda/bin/python
use_python(" /Users/User/anaconda/bin/python")
I am using all "data science pack" under Anaconda. Thet is why the corresponded python version was chosen. All required packages are installed and they often in use via Jupiter notebook
py_available()
[1] TRUE
Yes, as expected!
py_module_available("pandas")
[1] FALSE
Not available for some reason(((
Thank you in advance for the ideas))
SessionInfo for a case:
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] ru_RU.UTF-8/ru_RU.UTF-8/ru_RU.UTF-8/C/ru_RU.UTF-8/ru_RU.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] reticulate_1.1.0.9004
loaded via a namespace (and not attached):
[1] httr_1.3.1 compiler_3.4.1 R6_2.2.2 tools_3.4.1 withr_2.0.0 curl_2.8.1 memoise_1.1.0
[8] Rcpp_0.12.12 git2r_0.19.0 digest_0.6.12 jsonlite_1.5 devtools_1.13.3
I think you have to call use_python immediately after calling library(reticulate), before py_config or anything else.
That worked for me. More details in this question: Importing python module in R
You need to set the second argument of the function, so it should be:
For expample use_python("/users/my_user/Anaconda3/python.exe",required = TRUE)
DONT forget the required = TRUE
Related
When running sessionInfo() in Rstudio I get
R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.5.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
locale:
[1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] lubridate_1.8.0 fansi_1.0.3 assertthat_0.2.1 utf8_1.2.2 dplyr_1.0.10 R6_2.5.1 DBI_1.1.3 lifecycle_1.0.2 magrittr_2.0.3
[10] pillar_1.8.1 stringi_1.7.8 rlang_1.0.5 cli_3.4.0 rstudioapi_0.14 snakecase_0.11.0 vctrs_0.4.1 generics_0.1.3 tools_4.2.1
[19] stringr_1.4.1 glue_1.6.2 purrr_0.3.4 janitor_2.1.0 compiler_4.2.1 pkgconfig_2.0.3 tidyselect_1.1.2 tibble_3.1.8
When running the same on an R-session started in the terminal via R I get
R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur ... 10.16
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
locale:
[1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.2.1
As you can see the outputs differ:
RStudio says it's Monterey (which is correct), cli says it's Big Sur.
BLAS is missing
different packages are loaded via namespace
Both use the same .libPaths().
There's only one R in the path at /usr/local/bin/R.
This behaviour occurs on two different Macs, both with Monterey and R 4.2.1.
So why are the sessions different?
The running component is a copy of the utils::osVersion variable value. As explained in ?sessionInfo, that is set to the value used when R was compiled, which is typically 10.16 on Intel Macs.
Presumably RStudio and R.app replace that value with a correct one when run, but command line R doesn't.
If you build R yourself under Monterey, you'll see the correct value.
Regarding the packages loaded: RStudio loads a bunch of packages to support its API.
Regarding BLAS: I don't know, but it could be similar to the running issue, i.e. the front-end changed it.
I have recently updated INLA using the inla.update on my machine. Now everytime I try to run a function from the package, such as inla.mesh.2d I obtain the following error:
Error in inla.call.builtin() : INLA installation error; no such file
I tried uninstalling and reinstalling INLA package both in its testing and stable version but it still won't work.
I will paste below the output from sessionInfo():
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] it_IT.UTF-8/it_IT.UTF-8/it_IT.UTF-8/C/it_IT.UTF-8/it_IT.UTF-8
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] INLA_22.01.16 sp_1.4-5 foreach_1.5.1 Matrix_1.3-4
loaded via a namespace (and not attached):
[1] compiler_4.0.3 tools_4.0.3 tinytex_0.32 splines_4.0.3 codetools_0.2-18 grid_4.0.3
[7] iterators_1.0.13 xfun_0.23 lattice_0.20-44
Thank You!
The error you are getting may solve if you update your R to its latest version so INLA requirements are met. Restart, and it may resolve.
If this does not resolve the problem, installing directly from the R interface (vs RStudio) might fix the problem. This link explains how it is done and might be helpful if the first solution did not help.
https://groups.google.com/g/r-inla-discussion-group/c/f3LAE2VHZQw
I want to use warp function from terra package, but it seems the function is not available in my terra library. Is this a bug? Or could it relate to system gdal installation? I have not installed gdal outside R.
Edit: After more workaround I guess function terra::warp was in newer version renamed to terra::resample. So, there is maybe just inconsistency in help.
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=Czech_Czechia.1250 LC_CTYPE=Czech_Czechia.1250 LC_MONETARY=Czech_Czechia.1250
[4] LC_NUMERIC=C LC_TIME=Czech_Czechia.1250
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] terra_0.8-8 rgdal_1.5-16 landmap_0.0.3 raster_3.3-13 sp_1.4-2
loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2 yaml_2.2.1 Rcpp_1.0.5 codetools_0.2-16 grid_4.0.2
[7] lattice_0.20-41
Instead of a single warp method, terra has resample and project. With resample primarily to transform raster data to another resolution . This is for cases where this cannot be done with (dis)-aggregate --- which would otherwise be preferred. And with project primarily for transforming the data to another coordinate reference system.
In some ways this is a continuation of this older post, R packages with Rcpp and nloptr.
Mostly, this solution proved temporary, for several reasons, some minor, but mostly I am working to prefect this project for a cran submission and this remains the last hurdle.
That said, I attempted and failed to get this example running https://github.com/jyypma/nloptr/issues/39.
The error here is "..../sourceCpp_2.so Reason: image not found"
After, this I made a test package with nlopt installed into the 'inst' folder and 'makevars' and 'makevars.win' in the 'src' along with the test example from above.
This package is now on GitHub: https://github.com/shortyatz/Nlopt-and-Rcpp.
And gives me a similar error message to the one above.
Here is my session info:
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Rcpp_0.12.18
loaded via a namespace (and not attached):
[1] compiler_3.5.0 tools_3.5.0 RcppArmadillo_0.8.600.0.0 yaml_2.2.0
I have no idea how to make this problem reproducible, but here is a description of the problem nevertheless. I upgraded to R v 3.4.0 yesterday (sessionInfo() is below) and one of my RStudio projects couldn't update packages in packrat. After messing around with various "fixes" without success, I decided to delete packrat (packrat directory, project dir's .RStudio file) in the end. Unfortunately, I can't seem to re-initialize packrat in this project now. The following is the R output from
> packrat::init()
Initializing packrat project in directory:
- "~/my-project-path"
Error in isNamespaceLoaded(pkg) :
attempt to use zero-length variable name
In addition: Warning message:
In FUN(X[[i]], ...) : Package '' not available in repository or locally
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.4.0 magrittr_1.5 tools_3.4.0 yaml_2.1.14 stringi_1.1.5
[6] knitr_1.15.1 stringr_1.2.0 packrat_0.4.8-1 evaluate_0.10
Any help is very much appreciated. I thought about re-cloning the repo from github, but that would involve copy a large amount of files over from various directories that aren't under revision control currently.
Thanks!