1

I have tried conda install -c conda-forge r-Cubist, but no arm64 package in the arm64 channel.

The CRAN has the newest release which is the arm64 package, I tried to download the release version:macOS binaries: r-release (arm64), and put this package to /Users/rui/miniforge3/lib/R/library and run the code importr('Cubist')

but the error is:

rpy2.rinterface_lib.embedded.RRuntimeError: Error in library.dynam(lib, package, package.lib) : shared object ‘Cubist.dylib’ not found.

I checked the difference between the package downloaded from the CRAN package and the package downloaded from conda install -c conda-forge r-packagename, the lib folder of the former one has "so" file, and the latter one has "dylib" file.

How to use the arm64 r-package from the CRAN website in python? or how to get the 'dylib' file in the R package.

Update: Following the question Using conda to build and install local or custom R package, I tried

conda skeleton cran <pckg>
conda-build r-<pckg>
conda install --use-local r-<pcgk>

However, which needs r-base=3.5,the arm64 architecture requires r-base==4.2.1. Unsatisfiable dependencies for platform osx-arm64: {'r-base=3.5'}

Update:

The best way to solve this problem is to use the code that @onyambu provided and change the environment to google colab.

Rachel
  • 21
  • 1
  • 5
  • 2
    why not run the code in R, get the results and use them in Python? Why must you run R in Python? – Onyambu Aug 05 '22 at 18:20
  • Yes, good question. I am trying to reappear the code from https://github.com/mateoespinosa/remix?utm_source=catalyzex.com, which is a paper that should be compared with my research... – Rachel Aug 05 '22 at 18:24

1 Answers1

0

I cannot reproduce/work out your case since I'm running Windows, but you can try the following in Python:

from rpy2.robjects.packages import importr

# one-time execution to build & install the Cubist R package
utils= importr('utils')
utils.chooseCRANmirror(ind=1)
utils.install_packages(StrVector(['devtools']))
devtools = importr('devtools')
devtools.install_github('topepo/Cubist')

# if success you can then import the package
Cubist = importr('Cubist') 

The install_github may fails if you don't have a compiler toolchain already set up. (e.g., Windows R needs Rtools package)

kesh
  • 4,515
  • 2
  • 12
  • 20
  • Thanks for your suggestion. The description of devtools in this link:https://www.r-project.org/nosvn/pandoc/devtools.html. But it seems if I wanna use the devtools in python should use conda to install devtools, and there is the same question that no arm64 devtools in conda. – Rachel Aug 05 '22 at 20:53
  • Have you tried it? I don't see a reason why it wouldn't work because you are installing the package onto R lib folder not Python's. (yes, make sure xcode is installed) – kesh Aug 05 '22 at 21:12
  • Yes, I tried it. I use the code that you provided and make sure the xcode is installed, but the devtools.install_github() shows red(as the picture I added), and when I tried to install devtools in pycharm shows install failed. – Rachel Aug 05 '22 at 21:52
  • oops, my bad, it was missing the `importr('devtools')` line that I now added. Give it a try again. – kesh Aug 05 '22 at 22:19
  • Hey, I tried it. but the new error is```rpy2.rinterface_lib.embedded.RRuntimeError: Error: Failed to install 'Cubist' from GitHub: Could not find tools necessary to compile a package Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem. ``` – Rachel Aug 08 '22 at 13:57
  • https://stackoverflow.com/questions/37776377/error-when-installing-an-r-package-from-github-could-not-find-build-tools-neces, it's a link about how to fix this error, but I don't understand this answer. – Rachel Aug 08 '22 at 14:02
  • You probably don't have xcode (Mac's development environment) installed on your Mac. This is requirement to build R packages with C/C++ backends from source (e.g., GitHub). See [this Apple webpage](https://developer.apple.com/xcode/) helps to install it. (I'm on Windows so I cannot help you with exact howto. sorry.) – kesh Aug 08 '22 at 14:58
  • Thank you so much. The strange thing is I have downloaded the Xcode... – Rachel Aug 08 '22 at 15:27
  • Check [this link](https://johnmuschelli.com/neuroc/installing_devtools/index.html) out. " need to install Command Line Tools" – kesh Aug 08 '22 at 15:43
  • HEYYYYYY!!!!! Thank you so much! This code worked!!!! Finally, I changed the environment to google collab. – Rachel Aug 09 '22 at 14:07