Open mjbroerman opened 1 year ago
Can't see the compiler errors in this example, but I also encountered an "invoke_cargo" error when installing the package on a new computer this afternoon. Not an ideal solution, but I managed to get working by switching to the nightly rust build with:
rust_function("fn add(a:f64, b:f64) -> f64 { a + b }", toolchain="nightly")
If you don't have the nightly build, you can install it with rustup toolchain install nightly
Hm, that is strange. So you are using Macs, Macs are sometimes fragile. I remember there was an issue with cargo
-- somehow it was not available from within the session. There also might be some issue with transferring environment variables to another process, as we compile Rust code out-of-process using {processx}
.
Let's first diagnose the simplest problem, see for example this thread https://github.com/extendr/libR-sys/issues/54.
Check if your system("cargo --verion")
works from within R.
Can't see the compiler errors in this example, but I also encountered an "invoke_cargo" error when installing the package on a new computer this afternoon. Not an ideal solution, but I managed to get working by switching to the nightly rust build with:
rust_function("fn add(a:f64, b:f64) -> f64 { a + b }", toolchain="nightly")
If you don't have the nightly build, you can install it with
rustup toolchain install nightly
Just realized my other version of Rust was hopelessly outdated - switching to the nightly (or a newer version) probably won't do much for anyone else.
rust_function("fn add(a:f64, b:f64) -> f64 { a + b }", toolchain="nightly")
produces the same error for me.
system("cargo --version")
does not work!
sh: cargo: command not found
Warning message:
In system("cargo --version") : error in running command
But it does and returns cargo 1.63.0 (fd9c4297c 2022-07-01)
in the RStudio terminal and everywhere else.
I'm not sure how this works with R versions and Rosetta for the arm M1 Mac. Whereas I have :/Users/matt/.cargo/bin
in my $PATH
everywhere I have the command, with system("echo $PATH")
I have
/Users/matt/opt/miniconda3/bin:/Users/matt/opt/miniconda3/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:/opt/X11/bin:/Users/matt/Applications/quarto/bin:/Library/TeX/texbin:/usr/texbin:/Applications/RStudio.app/Contents/MacOS/quarto/bin:/Applications/RStudio.app/Contents/MacOS
So that at least seems to be a problem with different shell environments.
I tried this to get you compilation errors (attached) by navigating what I think is the build directory:
cd /private/var/folders/bp/l5qt50g13sndlz0x48jqqv300000gn/T/RtmpCsHcVC/file4add4132734f
cargo build
On Windows, I think we add it to PATH
here. Probably we can do the same on macOS?
https://github.com/extendr/rextendr/blob/05b4d4574b7f4e26fe9bc8c88df994a1001b17dc/R/helpers.r#L28
Ah, sorry, it's on non-Windows. Why doesn't this work?
I linked an issue from libR-sys. Something weird happens to R sessions on Mac, cargo
is not always available on path. One needs to manually add it to path inside R session and then try compiling code. The basic system("cargo --version")
verifies that cargo
is present.
Didn't we fix that in https://github.com/extendr/rextendr/pull/166?
Is this fixed?
Hi! Claus Wilke's nyhackr talk inspired me to try this. Thanks for all your hard work!
I got rust to build with
libR-sys
in theCargo.toml
, though I usedcurl
rather thanrustup
for installation as indicated, with:Then I installed
rextendr
. I tried your basic example:and got this:
I have both
x86_64
andarm64
versions ofR
installed. But myR.Version()
isx86_64
, the one I want. I did not do the step here because the lookup looked correct.Here's a reprex, but I thought the above was more informative.
Created on 2022-09-07 with reprex v2.0.2
Session info
``` r sessionInfo() #> 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] 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] rextendr_0.2.0.9000 #> #> loaded via a namespace (and not attached): #> [1] pillar_1.8.1 compiler_4.2.1 highr_0.9 R.methodsS3_1.8.2 #> [5] R.utils_2.12.0 tools_4.2.1 digest_0.6.29 jsonlite_1.8.0 #> [9] evaluate_0.16 lifecycle_1.0.1 tibble_3.1.8 R.cache_0.16.0 #> [13] pkgconfig_2.0.3 rlang_1.0.5 reprex_2.0.2 cli_3.3.0 #> [17] rstudioapi_0.14 yaml_2.3.5 xfun_0.32 fastmap_1.1.0 #> [21] withr_2.5.0 styler_1.7.0 stringr_1.4.1 dplyr_1.0.10 #> [25] knitr_1.40 generics_0.1.3 fs_1.5.2 vctrs_0.4.1 #> [29] tidyselect_1.1.2 glue_1.6.2 R6_2.5.1 processx_3.7.0 #> [33] fansi_1.0.3 rmarkdown_2.16 purrr_0.3.4 magrittr_2.0.3 #> [37] ps_1.7.1 htmltools_0.5.3 utf8_1.2.2 stringi_1.7.8 #> [41] brio_1.1.3 R.oo_1.25.0 ```