Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bus Error on Radian Launch #439

Open
eyayaw opened this issue Oct 9, 2023 · 21 comments
Open

Bus Error on Radian Launch #439

eyayaw opened this issue Oct 9, 2023 · 21 comments

Comments

@eyayaw
Copy link

eyayaw commented Oct 9, 2023

I think the error occurs on L22 in init.R of vscode-r:

https://github.com/REditorSupport/vscode-R/blob/70e3267c88052c8f299363719c18c776bdab139c/R/session/init.R#L22

Show Error
> radian

  *** caught bus error ***
address 0x100c466d0, cause 'invalid alignment'

Traceback:
 1: dyn.load(file, DLLpath = DLLpath, ...)
 2: library.dynam(lib, package, package.lib)
 3: loadNamespace(package, ...)
 4: doTryCatch(return(expr), name, parentenv, handler)
 5: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 6: tryCatchList(expr, classes, parentenv, handlers)
 7: tryCatch(loadNamespace(package, ...), error = function(e) e)
 8: FUN(X[[i]], ...)
 9: vapply(required_packages, requireNamespace, logical(1L), quietly = TRUE)
10: init_first()
11: eval(ei, envir)
12: eval(ei, envir)
13: withVisible(eval(ei, envir))
14: source("/Users/eyayaw/.vscode/extensions/reditorsupport.r-2.8.2/R/session/init.R",     chdir = TRUE, local = TRUE)
15: eval(quote(source("/Users/eyayaw/.vscode/extensions/reditorsupport.r-2.8.2/R/session/init.R",     chdir = TRUE, local = TRUE)), new.env())
16: eval(quote(source("/Users/eyayaw/.vscode/extensions/reditorsupport.r-2.8.2/R/session/init.R",     chdir = TRUE, local = TRUE)), new.env())
17: eval(expr, p)
18: eval(expr, p)
19: eval.parent(substitute(eval(quote(expr), envir)))
20: local(source("/Users/eyayaw/.vscode/extensions/reditorsupport.r-2.8.2/R/session/init.R",     chdir = TRUE, local = TRUE))
21: eval(ei, envir)
22: eval(ei, envir)
23: withVisible(eval(ei, envir))
24: source(file.path(Sys.getenv(if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"),     ".vscode-R", "init.R"))

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: 1
R is aborting now ...
zsh: bus error  radian
Radian version
> radian --version
radian version: 0.6.7
r executable: /Library/Frameworks/R.framework/Resources/bin/R
r version: 4.3.1
python executable: /opt/homebrew/opt/python@3.11/bin/python3.11
python version: 3.11.6
@MikeLydeamore
Copy link

I get the same error but specifically with the usethis package when I type usethis::. The error for me only occurs if I am in a renv session. If I use renv::deactivate(), the error goes away.

Radian version:

radian version: 0.6.7
r executable: /Library/Frameworks/R.framework/Resources/bin/R
r version: 4.3.0
python executable: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11
python version: 3.11.3

Other packages work fine with the namespace, and usethis works fine in the base R console (with renv). I am using vscode-R.

@eyayaw
Copy link
Author

eyayaw commented Oct 10, 2023

I get the same error but specifically with the usethis package when I type usethis::. The error for me only occurs if I am in a renv session. If I use renv::deactivate(), the error goes away.

Radian version:

radian version: 0.6.7
r executable: /Library/Frameworks/R.framework/Resources/bin/R
r version: 4.3.0
python executable: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11
python version: 3.11.3

Other packages work fine with the namespace, and usethis works fine in the base R console (with renv). I am using vscode-R.

For me, it is happening in a non-renv environment.

> R
R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
...

R> requireNamespace('renv')
Loading required namespace: renv
Failed with error:  ‘there is no package called ‘renv’’
R> grep('R_|renv',  names(Sys.getenv()), ignore.case=T, value=T)
 [1] "__CF_USER_TEXT_ENCODING" "R_ARCH"                 
 [3] "R_BROWSER"               "R_BZIPCMD"              
 [5] "R_DOC_DIR"               "R_GZIPCMD"              
 [7] "R_HOME"                  "R_INCLUDE_DIR"          
 [9] "R_LIBS_SITE"             "R_LIBS_USER"            
[11] "R_MAX_VSIZE"             "R_PAPERSIZE"            
[13] "R_PDFVIEWER"             "R_PLATFORM"             
[15] "R_PRINTCMD"              "R_QPDF"                 
[17] "R_RD4PDF"                "R_SESSION_TMPDIR"       
[19] "R_SHARE_DIR"             "R_STRIP_SHARED_LIB"     
[21] "R_STRIP_STATIC_LIB"      "R_SYSTEM_ABI"           
[23] "R_TEXI2DVICMD"           "R_UNZIPCMD"             
[25] "R_ZIPCMD"                "USER_ZDOTDIR" 

R> q()
Save workspace image? [y/n/c]: n

~/
> radian

 *** caught bus error ***
address 0x100c4e6d0, cause 'invalid alignment'
....

@boshek
Copy link

boshek commented Oct 11, 2023

I can also replicate this behaviour with these radian specs:

radian version: 0.6.3
r executable: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/bin/R
r version: 4.3.1
python executable: /Users/samalbers/mambaforge/bin/python3.9
python version: 3.9.16

A couple of observations:

  • If I try to create a R session in vscode in a non-renv environment (via the command palette) I get the same error as @eyayaw in the console. I also get this error from vscode:
The terminal process "/Users/samalbers/mambaforge/bin/radian '--no-save', '--no-restore', '--r-binary=/usr/local/bin/R'" terminated with exit code: 71.

I can, however, launch radian and R from the terminal and it works as normal. I can also initiate an renv project - however some packages will then throw the same error as above.

Adding this line:
R_PROFILE_USER=~/.Rprofile to my .Renviron file as suggested here allows us to start R but then the existing renv environments are not enabled.

I also have these settings in vs-code:

    "r.bracketedPaste": true,
   "r.rterm.mac": "/Users/samalbers/mambaforge/bin/radian",
   "r.rpath.mac": "/usr/local/bin/R", 
   "r.rterm.option": [
       "--no-save",
       "--no-restore",
       "--r-binary=/usr/local/bin/R"
   ],

@aswansyahputra
Copy link

It's also happening to me, either in {renv} or non -{renv} session and either in plain terminal or vscode terminal. Here is the screenshoot when I run radian in regular terminal with no {renv} activated:

image

@DivadNojnarg
Copy link

I also confirm the same issue (non renv) with radian on the M2 Mac. I don't have this issue on my old intel based Mac.

Screenshot 2023-10-13 at 09 57 32

@boshek
Copy link

boshek commented Oct 13, 2023

Update: this isn't a great workaround as you can't send code from the editor to the terminal out of the box.

One workaround that worked for me as to stop using radian as my default R terminal in vscode. So change the user settings to be something like this (on a mac):

 "r.rterm.mac": "/usr/local/bin/R",

Not an actual solution because radian is so awesome and I don't want to stop using it but at least this unblocked me. I had thought this was a vscode-R issue but now I'm not so sure.

@LeeMendelowitz
Copy link

I think this is a radian issue - I'm experiencing the caught bus error by using radian in the terminal with no VS Code involved. The error happens when I try to load a package with library.

I'm using R 4.3 installed by rig.

❯ radian --r-binary=/usr/local/bin/R-4.3-arm64 --version
radian version: 0.6.7
r executable: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/bin/R
r version: 4.3.1
python executable: /Users/lmendelowitz/.pyenv/versions/3.10.8/bin/python3.10
python version: 3.10.8
❯ radian --r-binary=/usr/local/bin/R-4.3-arm64
R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Platform: aarch64-apple-darwin20 (64-bit)

r$> library(dplyr)

 *** caught bus error ***
address 0x10394a6d0, cause 'invalid alignment'

Traceback:
 1: dyn.load(file, DLLpath = DLLpath, ...)
 2: library.dynam(lib, package, package.lib)
 3: loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]])
 4: namespaceImport(ns, loadNamespace(i, c(lib.loc, .libPaths()),     versionCheck = vI[[i]]), from = package)
 5: loadNamespace(package, lib.loc)
 6: doTryCatch(return(expr), name, parentenv, handler)
 7: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 8: tryCatchList(expr, classes, parentenv, handlers)
 9: tryCatch({    attr(package, "LibPath") <- which.lib.loc    ns <- loadNamespace(package, lib.loc)    env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)}, error = function(e) {    P <- if (!is.null(cc <- conditionCall(e)))         paste(" in", deparse(cc)[1L])    else ""    msg <- gettextf("package or namespace load failed for %s%s:\n %s",         sQuote(package), P, conditionMessage(e))    if (logical.return && !quietly)         message(paste("Error:", msg), domain = NA)    else stop(msg, call. = FALSE, domain = NA)})
10: library(dplyr)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

Selection:

I receive no error if I run without radian:

❯ /usr/local/bin/R-4.3-arm64

R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(dplyr)

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

>

@dewoller
Copy link

This is a radian error.

It does not happen with R alone, but it does happen with Radian

It occurs when loading packages. For me, it happens with packages pdftools, qpdf, rJava, tabulizer, tablulizerjars

These are all packages that I installed this morning. Packages I installed over the last 4 months still work.

I installed a new Python version yesterday (from python.org), v3.12.0, but radian has been and is running under asdf python version 3.11.3 previously.

It still crashes if I reinstall the R packages under radian or reinstall under standalone R session

It still crashes after uninstalling and reinstalling radian, using both pip and pipx

I love radian! Hope this helps

@randy3k
Copy link
Owner

randy3k commented Oct 18, 2023

I think this is a radian issue - I'm experiencing the caught bus error by using radian in the terminal with no VS Code involved. The error happens when I try to load a package with library.

I'm using R 4.3 installed by rig.

❯ radian --r-binary=/usr/local/bin/R-4.3-arm64 --version
radian version: 0.6.7
r executable: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/bin/R
r version: 4.3.1
python executable: /Users/lmendelowitz/.pyenv/versions/3.10.8/bin/python3.10
python version: 3.10.8
❯ radian --r-binary=/usr/local/bin/R-4.3-arm64
R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Platform: aarch64-apple-darwin20 (64-bit)

r$> library(dplyr)

 *** caught bus error ***
address 0x10394a6d0, cause 'invalid alignment'

Traceback:
 1: dyn.load(file, DLLpath = DLLpath, ...)
 2: library.dynam(lib, package, package.lib)
 3: loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]])
 4: namespaceImport(ns, loadNamespace(i, c(lib.loc, .libPaths()),     versionCheck = vI[[i]]), from = package)
 5: loadNamespace(package, lib.loc)
 6: doTryCatch(return(expr), name, parentenv, handler)
 7: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 8: tryCatchList(expr, classes, parentenv, handlers)
 9: tryCatch({    attr(package, "LibPath") <- which.lib.loc    ns <- loadNamespace(package, lib.loc)    env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)}, error = function(e) {    P <- if (!is.null(cc <- conditionCall(e)))         paste(" in", deparse(cc)[1L])    else ""    msg <- gettextf("package or namespace load failed for %s%s:\n %s",         sQuote(package), P, conditionMessage(e))    if (logical.return && !quietly)         message(paste("Error:", msg), domain = NA)    else stop(msg, call. = FALSE, domain = NA)})
10: library(dplyr)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

Selection:

I receive no error if I run without radian:

❯ /usr/local/bin/R-4.3-arm64

R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(dplyr)

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

>

There is a high chance that the python c runtime and R c time has some collision. You will have a better chance of success if you install both R and python using the same environment.

@randy3k
Copy link
Owner

randy3k commented Oct 18, 2023

It's also happening to me, either in {renv} or non -{renv} session and either in plain terminal or vscode terminal. Here is the screenshoot when I run radian in regular terminal with no {renv} activated:

image

@aswansyahputra how did you install R? Since you are using homebrew python, please make sure that you are also using homebrew R.

@randy3k
Copy link
Owner

randy3k commented Oct 18, 2023

I just tried radian with homebrew python and the official arm64 R on M2 mac. Everything is working fine..

@randy3k
Copy link
Owner

randy3k commented Oct 18, 2023

Ai, maybe it is not obvious enough, please make sure that both python, R and R packages are arm64.

@aswansyahputra
Copy link

aswansyahputra commented Oct 18, 2023

@aswansyahputra how did you install R? Since you are using homebrew python, please make sure that you are also using homebrew R.

@randy3k I downloaded and installed the R binary from the official page (I also have R installed in my other machine installed using rig), unfortunately the problem also happening there.

Here some additional infos:
image

@eyayaw
Copy link
Author

eyayaw commented Oct 24, 2023

Ai, maybe it is not obvious enough, please make sure that both python, R and R packages are arm64.

Unfortunately, that does not work on my m2. I tried with the homebrew python and r (brew install --cask r) and the official arm64 r.

CleanShot 2023-10-24 at 11 14 25

@psanker
Copy link

psanker commented Nov 10, 2023

I just tested @randy3k's statement about Homebrew R and Python being the same. I was having this issue when I had the Homebrew cask, but when I installed from the Homebrew formula, the error seems to have disappeared. I recommend others try this out. If your R executable (in $(brew --prefix)/bin) points to /Library/Frameworks/R.framework..., you have the cask installed. Try brew uninstall --cask r && brew install r.

I was running into the issue when radian would look for the exported members for autocompletion, specifically with cmdstanr. I thought that since cmdstanr has an external dependency it was the issue, but then rmarkdown had a problem. I wonder if there's some relationship to external libraries that could be hosing the dylib lookup?

This has the assumption that your Python is managed by Homebrew as well!

@dewoller
Copy link

Thank everyone, but especially @psanker 's last comment. My problem was that I was using the R install from R foundation. Uninstalling that, and brew install r fixed my problem. Radian, I am coming home!

@LeeMendelowitz
Copy link

What if I want to use radian on MacOS with pyenv and rig, which enables using multiple versions of Python and R? I use pyenv to compile and install Python and rig to maintain multiple versions of R.

I need to support multiple versions of Python and R for my projects and it would be great to find a way to be able to leverage radian in these situations.

@psanker
Copy link

psanker commented Nov 10, 2023

From the rchitect FAQ, it looks like you'll need to manually set the R_HOME environment variable and ensure that whatever installs R also includes libR.dylib. Since most of the users here seem to be macOS users, perhaps that's installed in an unexpected location in most cases?

Looking at the source, rchitect looks at $R_HOME/lib/libR.dylib. However, since this happens intermittently, perhaps there something else going on.

@eyayaw
Copy link
Author

eyayaw commented Nov 14, 2023

I just tested @randy3k's statement about Homebrew R and Python being the same. I was having this issue when I had the Homebrew cask, but when I installed from the Homebrew formula, the error seems to have disappeared. I recommend others try this out. If your R executable (in $(brew --prefix)/bin) points to /Library/Frameworks/R.framework..., you have the cask installed. Try brew uninstall --cask r && brew install r.

I was running into the issue when radian would look for the exported members for autocompletion, specifically with cmdstanr. I thought that since cmdstanr has an external dependency it was the issue, but then rmarkdown had a problem. I wonder if there's some relationship to external libraries that could be hosing the dylib lookup?

This has the assumption that your Python is managed by Homebrew as well!

Thanks. I can confirm that this works on my machine.

@LeeMendelowitz
Copy link

Setting R_HOME to point to R 4.3.1 installed using rig does not fix the problem for me. @randy3k any ideas would be greatly appreciated!

Here is an example loading dplyr from R 4.3.1 in rig. R_HOME is: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources. Everything works.

❯ R-4.3-arm64

R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> R.home()
[1] "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources"
> library(dplyr)

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

>

Now starting radian with R_HOME set, I get the bus error:

❯ R_HOME=/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources radian
R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Platform: aarch64-apple-darwin20 (64-bit)

r$> R.home()
[1] "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources"

r$> library(dplyr)

 *** caught bus error ***
address 0x100d326c0, cause 'invalid alignment'

Traceback:
 1: dyn.load(file, DLLpath = DLLpath, ...)
 2: library.dynam(lib, package, package.lib)
 3: loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]])
 4: namespaceImport(ns, loadNamespace(i, c(lib.loc, .libPaths()),     versionCheck = vI[[i]]), from = package)
 5: loadNamespace(package, lib.loc)
 6: doTryCatch(return(expr), name, parentenv, handler)
 7: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 8: tryCatchList(expr, classes, parentenv, handlers)
 9: tryCatch({    attr(package, "LibPath") <- which.lib.loc    ns <- loadNamespace(package, lib.loc)    env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)}, error = function(e) {    P <- if (!is.null(cc <- conditionCall(e)))         paste(" in", deparse(cc)[1L])    else ""    msg <- gettextf("package or namespace load failed for %s%s:\n %s",         sQuote(package), P, conditionMessage(e))    if (logical.return && !quietly)         message(paste("Error:", msg), domain = NA)    else stop(msg, call. = FALSE, domain = NA)})
10: library(dplyr)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

Selection:

I have a libR.dylib:

❯ ls -la /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib
total 19760
drwxrwxr-x  17 root  admin      544 Sep  8 07:50 .
drwxrwxr-x  17 root  admin      544 Sep  8 07:50 ..
-rwxrwxr-x   1 root  admin  4031760 Sep  8 07:50 libR.dylib
drwxrwxr-x   3 root  admin       96 Sep  8 07:50 libR.dylib.dSYM
-rwxrwxr-x   1 root  admin   193872 Sep  8 07:50 libRblas.0.dylib
drwxrwxr-x   3 root  admin       96 Sep  8 07:50 libRblas.0.dylib.dSYM
lrwxrwxr-x   1 root  admin       16 Sep  8 07:50 libRblas.dylib -> libRblas.0.dylib
drwxrwxr-x   3 root  admin       96 Sep  8 07:50 libRblas.dylib.dSYM
-rwxrwxr-x   1 root  admin   154464 Sep  8 07:50 libRblas.vecLib.dylib
drwxrwxr-x   3 root  admin       96 Sep  8 07:50 libRblas.vecLib.dylib.dSYM
-rwxrwxr-x   1 root  admin  1713120 Sep  8 07:50 libRlapack.dylib
drwxrwxr-x   3 root  admin       96 Sep  8 07:50 libRlapack.dylib.dSYM
-rw-rw-r--   1 root  admin   157712 Sep  8 07:50 libgcc_s.1.1.dylib
-rwxrwxr-x   1 root  admin  1864864 Sep  8 07:50 libgfortran.5.dylib
-rwxrwxr-x   1 root  admin  1613904 Sep  8 07:50 libomp.dylib
-rwxrwxr-x   1 root  admin   366800 Sep  8 07:50 libquadmath.0.dylib
drwxrwxr-x   3 root  admin       96 Sep  8 07:50 pkgconfig
❯ R_HOME=/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources radian --version
radian version: 0.6.8
r executable: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/bin/R
r version: 4.3.1
python executable: /Users/lmendelowitz/.pyenv/versions/3.11.6/bin/python3.11
python version: 3.11.6

@arbelt
Copy link

arbelt commented Nov 15, 2023

Setting R_HOME also did not do the trick for me. And using Homebrew R isn't really a solution because (last I checked) it prevents the use of CRAN binary packages.

If it helps give any clues: reinstalling problematic packages from source makes the issue goes away (e.g., using renv, renv::install("dplyr", type = "source") — but there were other packages, like httpuv). But this is too time-consuming across multiple projects to be a real solution, and identifying the culprit packages doesn't seem entirely trivial, esp with many projects that are using renv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants