radian: Bus Error on Radian Launch

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

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 4
  • Comments: 33 (6 by maintainers)

Most upvoted comments

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.

Thanks for the reproducible example. I am able to reproduce the error on my mac. by

install.packages("rlang", repos = "https://p3m.dev/cran/latest")

Having a look at the rlang.so

(=)-~$ otool -L /Library/Frameworks/R.framework/Resources/library/rlang/libs/rlang.so
/Library/Frameworks/R.framework/Resources/library/rlang/libs/rlang.so:
	rlang.so (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)

Compare to CRAN’s version

(=)-~$ otool -L /Library/Frameworks/R.framework/Resources/library/rlang/libs/rlang.so
/Library/Frameworks/R.framework/Resources/library/rlang/libs/rlang.so:
	rlang.so (compatibility version 0.0.0, current version 0.0.0)
	/Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libR.dylib (compatibility version 4.5.0, current version 4.5.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.100.5)

It seems that the one from RSPM is missing the linking to libR.dylib.

The library can be forced to be inserted on macOS using

DYLD_INSERT_LIBRARIES=/Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libR.dylib radian

and on unix

LD_PRELOAD=<PATH to libR.so> radian

Note that it is only a workaround. Ideally, the packages from RSPM should have linked to libR.so/libR.dylib.

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.

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

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

>

The Bus Error was actually happening in regular radian sessions without renv. Finally tracked it down. package_info() told me that one package, namely Matrix, was installed from RSPM instead of CRAN. When and how that happened is beyond me.

Screenshot 2024-12-17 at 05 49 08

Every package that had Matrix as a dependency caused the Bus Error. Reinstalling Matrix via install.packages("Matrix") with no special settings completely fixed the problem.

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!