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

Errors when loading RCDT provided by rPackages.RCDT #344213

Closed
HVinther opened this issue Sep 24, 2024 · 21 comments
Closed

Errors when loading RCDT provided by rPackages.RCDT #344213

HVinther opened this issue Sep 24, 2024 · 21 comments

Comments

@HVinther
Copy link

Describe the bug

The R package RCDT does not load properly. In a terminal R session, the package unexpectedly provides a prompt, when attempting to load the package with library("RCDT"). Entering a string just gives a new prompt. Entering an integer gives a segmentation fault.

When attempting the same inside the console of the ide positron, the package does load and is useable, but it gives a warning about the author string.

When trying to load the package using callr (used in pipeline tools such as targets), the call errors out and also gives the warning message described above.

The three scenarios can be seen in the screenshots.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Create temporary enviroment nix-shell -p R rPackages.callr rPackages.RCDT
  2. Enter an R session R
  3. Call library("RCDT")

Alternatively

  1. Create temporary enviroment nix-shell -p R rPackages.callr rPackages.RCDT
  2. Enter the ide Positron
  3. Call library("RCDT") in the console

Alternatively

  1. Create temporary enviroment nix-shell -p R rPackages.callr rPackages.RCDT
  2. Enter the ide Positron
  3. Call callr::r(\(x){version},package = "RCDT") in the console

Expected behavior

Package loads with no errors or warnings. Expected behaviour can be seen by installing the docker image rocker/r2u and then installing RCDT and callr inside the image using install.packages.

Screenshots

In terminal session:
image

In positron ide:
image

Using with callr in positron ide:
image

Additional context

Issue originally discovered when using the {rix} for R and thus reported in (ropensci/rix#329 (comment)) but found to persist using just nix.

Notify maintainers

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.10.11-1-default, openSUSE Tumbleweed, noversion, nobuild`
 - multi-user?: `no`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.24.1`
 - nixpkgs: `/home/hvl/.nix-defexpr/channels/nixpkgs`

Add a 👍 reaction to issues you find important.

@b-rodrigues
Copy link
Contributor

I can indeed reproduce. Also I tried with RStudio using

nix-shell -p "rstudioWrapper.override{packages = with rPackages; [ RCDT ];}"

and trying to load RCDT in RStudio makes it crash. But I don't get anything about the author names and such.

@Kupac
Copy link
Contributor

Kupac commented Sep 24, 2024

Can't reproduce on x86_64-linux. I could run the first example from the vignette just fine. Could it be an mac issue?

> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: NixOS 24.11 (Vicuna)

Matrix products: default
BLAS/LAPACK: /nix/store/bgl9cw31jlh61vq5mabpzf62lqc5bv31-blas-3/lib/libblas.so.3;  LAPACK version 3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=hu_HU.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=hu_HU.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=hu_HU.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=hu_HU.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Brussels
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RCDT_1.3.0

loaded via a namespace (and not attached):
 [1] digest_0.6.36        rgl_1.3.1            R6_2.5.1            
 [4] base64enc_0.1-3      fastmap_1.2.0        xfun_0.47           
 [7] gtools_3.9.5         magrittr_2.0.3       KernSmooth_2.23-24  
[10] knitr_1.48           htmltools_0.5.8.1    cli_3.6.3           
[13] bitops_1.0-8         scatterplot3d_0.3-44 caTools_1.18.2      
[16] Rvcg_0.23            colorsGen_1.0.0      Polychrome_1.5.1    
[19] compiler_4.4.1       tools_4.4.1          Rcpp_1.0.13         
[22] gplots_3.1.3.1       colorspace_2.1-1     jsonlite_1.8.8      
[25] rlang_1.1.4          htmlwidgets_1.6.4   

@b-rodrigues
Copy link
Contributor

I'm on opensuse and so is OP, but you're on NixOs, right? could this be related to some graphics issue?

@jbedo
Copy link
Contributor

jbedo commented Sep 24, 2024

That prompt is the standard R signal handler that gets triggered on a SIGSEGV, e.g.,:

> dyn.load("/nix/store/3dyw8dzj9ab4m8hv5dpyx7zii8d0w6fi-glibc-2.39-52/lib/libc.so.6")
> .Call("raise","SIGSEGV")

 *** caught segfault ***
address 0x100000002, cause 'memory not mapped'

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:

No idea why it's not showing the full message though. Likely the package has memory errors which are triggering a segfault on load.

I also couldn't reproduce the error, same sessionInfo() as Kupac. I further verified with valgrind that there are no memory errors occuring on load. I suggest verifying the issue exists with --pure as this seems likely to be a side effect.

@jbedo
Copy link
Contributor

jbedo commented Sep 24, 2024

Posting your sessionInfo() would also be helpful.

@HVinther
Copy link
Author

So when running nix-shell --pure -p R rPackages.callr rPackages.RCDT, I can indeed load RCDT an run the first example in the vignette except for plotting. The only errors there seemed related to establishing a connecting with x11.

> library(RCDT)
Warning messages:
1: In rgl.init(initValue, onlyNULL) : RGL: unable to open X11 display
2: 'rgl.init' failed, running with 'rgl.useNULL = TRUE'. 

and

plotDelaunay(
  del, type = "n", asp = 1, fillcolor = "distinct", lwd_borders = 3,
  xlab = NA, ylab = NA, axes = FALSE
)
Authorization required, but no authorization protocol specified

Error in .External2(C_X11, d$display, d$width, d$height, d$pointsize,  : 
  unable to start device X11cairo
In addition: Warning message:
In (function (display = "", width, height, pointsize, gamma, bg,  :
  unable to open connection to X11 display '

When calling session info in the pure shell I get the following:

> sessionInfo() 
R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: openSUSE Tumbleweed

Matrix products: default
BLAS/LAPACK: /nix/store/jdbpn0j9xj7rqgyq9q3274x3ampykw33-blas-3/lib/libblas.so.3;  LAPACK version 3.12.0

locale:
[1] C

time zone: Europe/Copenhagen
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.4.1

Which seems the same as calling it in the impure shell, there I however get some warnings during startup of the R-session, which should also be visible in the screenshots

During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C" 
2: Setting LC_COLLATE failed, using "C" 
3: Setting LC_TIME failed, using "C" 
4: Setting LC_MESSAGES failed, using "C" 
5: Setting LC_MONETARY failed, using "C" 
6: Setting LC_PAPER failed, using "C" 
7: Setting LC_MEASUREMENT failed, using "C" 
> sessionInfo() 
R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: openSUSE Tumbleweed

Matrix products: default
BLAS/LAPACK: /nix/store/jdbpn0j9xj7rqgyq9q3274x3ampykw33-blas-3/lib/libblas.so.3;  LAPACK version 3.12.0

locale:
[1] C

time zone: Europe/Copenhagen
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.4.1

@jbedo
Copy link
Contributor

jbedo commented Sep 25, 2024

The X authorisation issues is a bit strange, DISPLAY shouldn't get unset by --pure. Maybe check it's still set and you could try adjusting your X11 authorisation with xhost +local: or something similar. The segfault seems to be some interaction with your OS though, at a guess due to locale since you're getting a lot of errors around that when loading R and when you load the package in positron.

@b-rodrigues
Copy link
Contributor

b-rodrigues commented Sep 25, 2024

I think that the issue is actually rPackages.rgl: trying it in a shell results in the same failure.

> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: openSUSE Tumbleweed-Slowroll

Matrix products: default
BLAS/LAPACK: /nix/store/bgl9cw31jlh61vq5mabpzf62lqc5bv31-blas-3/lib/libblas.so.3;  LAPACK version 3.12.0

locale:
[1] C

time zone: Europe/Luxembourg
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.4.1

then loading rgl in a pure shell:

> library(rgl)
Selection: 
Selection: 
Selection: 1
Segmentation fault (core dumped)

[nix-shell:~]$ 

I even tried with another package that has rgl as a dependency, same story:

> library(bios2mds)
Loading required package: amap
Loading required package: e1071
Loading required package: scales
Loading required package: cluster
Loading required package: rgl
Selection: 1
Segmentation fault (core dumped)

[nix-shell:~]$ 

@b-rodrigues
Copy link
Contributor

@Kupac
Copy link
Contributor

Kupac commented Sep 25, 2024

I wouldn't know because I can't reproduce the rgl segfault either.

BTW, the X connection in --pure shell can be restored if you keep the display and xauthority variables. Like so:
nix-shell --pure --keep DISPLAY --keep XAUTHORITY -p 'radianWrapper.override{packages = [ rPackages.rgl ];}'

(or rWrapper)

@HVinther
Copy link
Author

I wouldn't know because I can't reproduce the rgl segfault either.

BTW, the X connection in --pure shell can be restored if you keep the display and xauthority variables. Like so: nix-shell --pure --keep DISPLAY --keep XAUTHORITY -p 'radianWrapper.override{packages = [ rPackages.rgl ];}'

(or rWrapper)

I tried the nix-shell arguments proposed and loading rgl inside radian. This gave more traceback information than in R session, but segfault remains.

localhost:~> nix-shell --pure --keep DISPLAY --keep XAUTHORITY -p 'radianWrapper.override{packages = [ rPackages.rgl ];}'

[nix-shell:~]$ radian
R version 4.4.1 (2024-06-14) -- "Race for Your Life"
Platform: x86_64-pc-linux-gnu (64-bit)

r$> library(rgl)

 *** caught segfault ***
address 0x20, cause 'memory not mapped'

Traceback:
 1: rgl.init(initValue, onlyNULL)
 2: fun(libname, pkgname)
 3: doTryCatch(return(expr), name, parentenv, handler)
 4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 5: tryCatchList(expr, classes, parentenv, handlers)
 6: tryCatch(fun(libname, pkgname), error = identity)
 7: runHook(".onLoad", env, package.lib, package)
 8: loadNamespace(package, lib.loc)
 9: doTryCatch(return(expr), name, parentenv, handler)
10: tryCatchOne(expr, names, parentenv, handlers[[1L]])
11: tryCatchList(expr, classes, parentenv, handlers)
12: 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)})
13: library(rgl)

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:

@HVinther
Copy link
Author

@HVinther
Copy link
Author

Inspired by nix-community/nixGL#145 (comment) i created a nix shell using the following lines in which I loaded rgl without error.

export NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/7b1777b1e47d730dea558a5cd9b381cdee7b4f14.tar.gz

$(nix-build https://github.com/nix-community/nixGL/archive/master.tar.gz -A nixGLIntel)/bin/nixGLIntel \
    nix-shell -p R rPackages.rgl --run R

I similarly tried creating a shell with RCDT:

export NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/7b1777b1e47d730dea558a5cd9b381cdee7b4f14.tar.gz

$(nix-build https://github.com/nix-community/nixGL/archive/master.tar.gz -A nixGLIntel)/bin/nixGLIntel \
    nix-shell -p R rPackages.RCDT --run R

This allowed me to run the first example of the vignette without problem.

@b-rodrigues
Copy link
Contributor

Very cool, I guess this is what we should do in situations where Nix gets used outside of NixOS! I think that we could document this in https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/r.section.md, what do you think @jbedo ?

@jbedo
Copy link
Contributor

jbedo commented Sep 26, 2024

Not really an R problem, would be good to document elsewhere and cross reference in R. Also, lack of GL shouldn't cause a segfault so might be worth opening an issue upstream with RGL.

@philipp-baumann
Copy link
Contributor

philipp-baumann commented Sep 27, 2024

rix_tests/test_RCDT onmain [!?] took 1m 3.9s4% ➜ nix-shell --pure -p R rPackages.callr rPackages.RCDT

[nix-shell:~/rix_tests/test_RCDT]$ R

R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin23.4.0 (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.

During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C" 
2: Setting LC_COLLATE failed, using "C" 
3: Setting LC_TIME failed, using "C" 
4: Setting LC_MESSAGES failed, using "C" 
5: Setting LC_MONETARY failed, using "C" 
> library(RCDT)
> # vertices
R <- sqrt((5-sqrt(5))/10)     # outer radius
r <- sqrt((25-11*sqrt(5))/10) # circumradius of the inner pentagon
k <- pi/180 # factor to convert degrees to radians
X <- R * vapply(0L:4L, function(i) cos(k * (90+72*i)), numeric(1L))
Y <- R * vapply(0L:4L, function(i) sin(k * (90+72*i)), numeric(1L))
x <- r * vapply(0L:4L, function(i) cos(k * (126+72*i)), numeric(1L))
y <- r * vapply(0L:4L, function(i) sin(k * (126+72*i)), numeric(1L))
vertices <- rbind(
  c(X[1L], Y[1L]),
  c(x[1L], y[1L]),
  c(X[2L], Y[2L]),
  c(x[2L], y[2L]),
  c(X[3L], Y[3L]),
  c(x[3L], y[3L]),
  c(X[4L], Y[4L]),
  c(x[4L], y[4L]),
  c(X[5L], Y[5L]),
  c(x[5L], y[5L])
)
# constraint edges: indices
edges <- cbind(1L:10L, c(2L:10L, 1L))
# constrained Delaunay triangulation
del <- delaunay(vertices, edges)
# plot
opar <- par(mar = c(0, 0, 0, 0))
plotDelaunay(
  del, type = "n", asp = 1, fillcolor = "distinct", lwd_borders = 3,
  xlab = NA, ylab = NA, axes = FALSE
)
> sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: aarch64-apple-darwin23.4.0 (64-bit)
Running under: macOS Sonoma 14.2.1

Matrix products: default
BLAS:   /nix/store/4kqdh4mk7fjnly8daba1cjycj815055m-blas-3/lib/libblas.dylib 
LAPACK: /nix/store/x7im9yssybhdqwif49y96pwb57vhrds4-openblas-0.3.26/lib/libopenblasp-r0.3.26.dylib;  LAPACK version 3.12.0

locale:
[1] C

time zone: Europe/Zurich
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RCDT_1.3.0

loaded via a namespace (and not attached):
 [1] digest_0.6.35        rgl_1.3.1            R6_2.5.1            
 [4] base64enc_0.1-3      fastmap_1.1.1        xfun_0.42           
 [7] gtools_3.9.5         magrittr_2.0.3       KernSmooth_2.23-22  
[10] knitr_1.45           htmltools_0.5.7      cli_3.6.2           
[13] bitops_1.0-7         scatterplot3d_0.3-44 caTools_1.18.2      
[16] Rvcg_0.22.2          colorsGen_1.0.0      Polychrome_1.5.1    
[19] compiler_4.3.3       tools_4.3.3          Rcpp_1.0.12         
[22] gplots_3.1.3.1       colorspace_2.1-0     jsonlite_1.8.8      
[25] rlang_1.1.3          htmlwidgets_1.6.4   
> .libPaths()
 [1] "/nix/store/i2lrv63rk1vnbzv1wdx96z3qh3sky2m9-r-callr-3.7.5/library"                        
 [2] "/nix/store/9h3wcnfvpllzfzpz2a3dxck1pc77llsj-r-processx-3.8.4/library"                     
 [3] "/nix/store/5bslj3jdv339s8fs0xiq5c6b2mqnyafg-r-ps-1.7.6/library"                           
 [4] "/nix/store/ncxfsalamqngfmlm6hrfq6d0sz3qwpfh-r-R6-2.5.1/library"                           
 [5] "/nix/store/ymajv0n37q1i9wnzwq4vxj6y0ib3plpi-r-RCDT-1.3.0/library"                         
 [6] "/nix/store/724kqs057i1qkk6kff70f77qm56d4yzg-r-BH-1.84.0-0/library"                        
 [7] "/nix/store/ngagk6z8adkn4kya0nbjcffnkcnzkabd-r-colorsGen-1.0.0/library"                    
 [8] "/nix/store/7d3042dp9qf19arb2al89dh28jwhc8s6-r-colorspace-2.1-0/library"                   
 [9] "/nix/store/pdks4yipwimcdajanjyp2r3a9sf03frj-r-gplots-3.1.3.1/library"                     
[10] "/nix/store/xz5hck83vjlrg0dl31y9pjxrnnwhi59q-r-caTools-1.18.2/library"                     
[11] "/nix/store/3nd3fy6dihivqagf60saqjc03fav9n96-r-bitops-1.0-7/library"                       
[12] "/nix/store/58bib2y8mm7ybfm0z5jpvf04m8mblv3q-r-gtools-3.9.5/library"                       
[13] "/nix/store/2840qlij0qgfvzqq74v3aah52nc8pab9-r-KernSmooth-2.23-22/library"                 
[14] "/nix/store/31ml30rgvq7z8zy3bv705b7sw9dm98lx-r-Polychrome-1.5.1/library"                   
[15] "/nix/store/24hri2m92xqrha8nwd4xb95jyqzly7r0-r-scatterplot3d-0.3-44/library"               
[16] "/nix/store/dc61882nv54b63g7am60xg76amcyh8q0-r-Rcpp-1.0.12/library"                        
[17] "/nix/store/942q1h7rgi7wdl9g9nl9icrsh1xlgmk4-r-RcppArmadillo-0.12.8.1.0/library"           
[18] "/nix/store/97q5fm6lwn0hzxxfxdl1pw8ks2amch5i-r-rgl-1.3.1/library"                          
[19] "/nix/store/j6vyl4jphvixys5x0ad52njqk4s93wcw-r-base64enc-0.1-3/library"                    
[20] "/nix/store/7m0bajvqhng7dsg5lr1yzkmff9wg8gf9-r-htmltools-0.5.7/library"                    
[21] "/nix/store/cgd4aqg763lp0vvzh9b24ci7dkkzkw6r-r-digest-0.6.35/library"                      
[22] "/nix/store/49rqk71cds9b0fy6qjcpivv0mqivrbf6-r-ellipsis-0.3.2/library"                     
[23] "/nix/store/xz0nk9x7gmgc88xw6wmq6lkppdvxc60j-r-rlang-1.1.3/library"                        
[24] "/nix/store/yriy7b600sqac2crkq6mpk1i41hl9k8y-r-fastmap-1.1.1/library"                      
[25] "/nix/store/69i6h6vnkbdnkfpr96pi9jzrp96g2fnm-r-htmlwidgets-1.6.4/library"                  
[26] "/nix/store/x5whgkl6573w39j9zhraq1090dbk5ag9-r-jsonlite-1.8.8/library"                     
[27] "/nix/store/zka8py06kx4hvmjl5cw17bdfpzqj3k2n-r-knitr-1.45/library"                         
[28] "/nix/store/n2d764m3yvl8qrq7p0ymbi0d09ahvpkw-r-evaluate-0.23/library"                      
[29] "/nix/store/705g6a21mwg4hbcdz89n34xb1jw93lir-r-highr-0.10/library"                         
[30] "/nix/store/0d5ks6cls6ja8izqaydy96pfsnnw6hmz-r-xfun-0.42/library"                          
[31] "/nix/store/mmv11vq65x9d6p6zfwfv78q4x18jy50s-r-yaml-2.3.8/library"                         
[32] "/nix/store/p6g3igq0sym2ndkaz64fqxmxmk19kqs8-r-rmarkdown-2.26/library"                     
[33] "/nix/store/y6yk3q9fydvzih1d51b8wzqr85a9hgnb-r-bslib-0.6.2/library"                        
[34] "/nix/store/263q8ny5sf6y0jln1j42vawrni5yihiw-r-cachem-1.0.8/library"                       
[35] "/nix/store/8n0abpp67f8ygxfh5xncagagimypgvm5-r-jquerylib-0.1.4/library"                    
[36] "/nix/store/g9dbrhl1q2hv40smh9gq242qfd5l5lz6-r-lifecycle-1.0.4/library"                    
[37] "/nix/store/0ckvnrldgdxk2ngx7ppljs5gp7i4ybai-r-cli-3.6.2/library"                          
[38] "/nix/store/d03rnf4js0ch0vn24cbj06w2yyni8dbw-r-glue-1.7.0/library"                         
[39] "/nix/store/x3lh2w2r59n5n471bk07x5jd5pxlxfsw-r-memoise-2.0.1/library"                      
[40] "/nix/store/9wicxxwxl5cy4vq6xavidx5hg33jyfgc-r-mime-0.12/library"                          
[41] "/nix/store/762b9hgq2bgvzf7ym1m2i3gzf9kbjsb2-r-sass-0.4.9/library"                         
[42] "/nix/store/l1aa6fs8kz7q81x8vjav4zd3n2awvnyn-r-fs-1.6.3/library"                           
[43] "/nix/store/j4sgi9whay0ldghkrgascb7i5cxfiy18-r-rappdirs-0.3.3/library"                     
[44] "/nix/store/qlrw9n9rf43mnvldvag5w5y7fzsbwcv9-r-fontawesome-0.5.2/library"                  
[45] "/nix/store/ckvriqfsqk82xf8j3k1036x4a7534pj9-r-tinytex-0.50/library"                       
[46] "/nix/store/wqxsnk1qff2dc23q3lijiz4syzysxcyw-r-magrittr-2.0.3/library"                     
[47] "/nix/store/8jwj3ambqs3j19l0jnw9rwabwkyawibm-r-Rvcg-0.22.2/library"                        
[48] "/nix/store/pha2c9f9vd2lfka2v5aq3lp46pcbarik-r-RcppEigen-0.3.4.0.0/library"                
[49] "/nix/store/5ylipgzwqx1xs6cadrv5wxrjsial7wlr-apple-framework-CoreFoundation-11.0.0/Library"
[50] "/nix/store/mcl9p6myk7dszrij2c1y87qigv5mh17y-R-4.3.3/lib/R/library"

@HVinther what is your libpath? i have had many segmentation faults before on macOS because of linked system libs and permission issues, unfortunately in nix the default is that R_LIBS_USER gets set, which is for your host's R, unless you are using a temporary nix-shell. This is why we have the .Rprofile hack with rix::rix_init() also called in rix::rix(). Unfortunately, rix 12.0.2 suffered from a bug writing empty .Rprofile files. So my suggestion is to check your .libPaths() output and make sure you have the custom .Rprofile.

@b-rodrigues
Copy link
Contributor

If you don't have it, run rix_init(rprofile_action = "overwrite") in the path of the project to generate it! That's a good suggestion @philipp-baumann didn't think of that!

@HVinther
Copy link
Author

rix_tests/test_RCDT onmain [!?] took 1m 3.9s4% ➜ nix-shell --pure -p R rPackages.callr rPackages.RCDT

[nix-shell:~/rix_tests/test_RCDT]$ R

R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin23.4.0 (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.

During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C" 
2: Setting LC_COLLATE failed, using "C" 
3: Setting LC_TIME failed, using "C" 
4: Setting LC_MESSAGES failed, using "C" 
5: Setting LC_MONETARY failed, using "C" 
> library(RCDT)
> # vertices
R <- sqrt((5-sqrt(5))/10)     # outer radius
r <- sqrt((25-11*sqrt(5))/10) # circumradius of the inner pentagon
k <- pi/180 # factor to convert degrees to radians
X <- R * vapply(0L:4L, function(i) cos(k * (90+72*i)), numeric(1L))
Y <- R * vapply(0L:4L, function(i) sin(k * (90+72*i)), numeric(1L))
x <- r * vapply(0L:4L, function(i) cos(k * (126+72*i)), numeric(1L))
y <- r * vapply(0L:4L, function(i) sin(k * (126+72*i)), numeric(1L))
vertices <- rbind(
  c(X[1L], Y[1L]),
  c(x[1L], y[1L]),
  c(X[2L], Y[2L]),
  c(x[2L], y[2L]),
  c(X[3L], Y[3L]),
  c(x[3L], y[3L]),
  c(X[4L], Y[4L]),
  c(x[4L], y[4L]),
  c(X[5L], Y[5L]),
  c(x[5L], y[5L])
)
# constraint edges: indices
edges <- cbind(1L:10L, c(2L:10L, 1L))
# constrained Delaunay triangulation
del <- delaunay(vertices, edges)
# plot
opar <- par(mar = c(0, 0, 0, 0))
plotDelaunay(
  del, type = "n", asp = 1, fillcolor = "distinct", lwd_borders = 3,
  xlab = NA, ylab = NA, axes = FALSE
)
> sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: aarch64-apple-darwin23.4.0 (64-bit)
Running under: macOS Sonoma 14.2.1

Matrix products: default
BLAS:   /nix/store/4kqdh4mk7fjnly8daba1cjycj815055m-blas-3/lib/libblas.dylib 
LAPACK: /nix/store/x7im9yssybhdqwif49y96pwb57vhrds4-openblas-0.3.26/lib/libopenblasp-r0.3.26.dylib;  LAPACK version 3.12.0

locale:
[1] C

time zone: Europe/Zurich
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RCDT_1.3.0

loaded via a namespace (and not attached):
 [1] digest_0.6.35        rgl_1.3.1            R6_2.5.1            
 [4] base64enc_0.1-3      fastmap_1.1.1        xfun_0.42           
 [7] gtools_3.9.5         magrittr_2.0.3       KernSmooth_2.23-22  
[10] knitr_1.45           htmltools_0.5.7      cli_3.6.2           
[13] bitops_1.0-7         scatterplot3d_0.3-44 caTools_1.18.2      
[16] Rvcg_0.22.2          colorsGen_1.0.0      Polychrome_1.5.1    
[19] compiler_4.3.3       tools_4.3.3          Rcpp_1.0.12         
[22] gplots_3.1.3.1       colorspace_2.1-0     jsonlite_1.8.8      
[25] rlang_1.1.3          htmlwidgets_1.6.4   
> .libPaths()
 [1] "/nix/store/i2lrv63rk1vnbzv1wdx96z3qh3sky2m9-r-callr-3.7.5/library"                        
 [2] "/nix/store/9h3wcnfvpllzfzpz2a3dxck1pc77llsj-r-processx-3.8.4/library"                     
 [3] "/nix/store/5bslj3jdv339s8fs0xiq5c6b2mqnyafg-r-ps-1.7.6/library"                           
 [4] "/nix/store/ncxfsalamqngfmlm6hrfq6d0sz3qwpfh-r-R6-2.5.1/library"                           
 [5] "/nix/store/ymajv0n37q1i9wnzwq4vxj6y0ib3plpi-r-RCDT-1.3.0/library"                         
 [6] "/nix/store/724kqs057i1qkk6kff70f77qm56d4yzg-r-BH-1.84.0-0/library"                        
 [7] "/nix/store/ngagk6z8adkn4kya0nbjcffnkcnzkabd-r-colorsGen-1.0.0/library"                    
 [8] "/nix/store/7d3042dp9qf19arb2al89dh28jwhc8s6-r-colorspace-2.1-0/library"                   
 [9] "/nix/store/pdks4yipwimcdajanjyp2r3a9sf03frj-r-gplots-3.1.3.1/library"                     
[10] "/nix/store/xz5hck83vjlrg0dl31y9pjxrnnwhi59q-r-caTools-1.18.2/library"                     
[11] "/nix/store/3nd3fy6dihivqagf60saqjc03fav9n96-r-bitops-1.0-7/library"                       
[12] "/nix/store/58bib2y8mm7ybfm0z5jpvf04m8mblv3q-r-gtools-3.9.5/library"                       
[13] "/nix/store/2840qlij0qgfvzqq74v3aah52nc8pab9-r-KernSmooth-2.23-22/library"                 
[14] "/nix/store/31ml30rgvq7z8zy3bv705b7sw9dm98lx-r-Polychrome-1.5.1/library"                   
[15] "/nix/store/24hri2m92xqrha8nwd4xb95jyqzly7r0-r-scatterplot3d-0.3-44/library"               
[16] "/nix/store/dc61882nv54b63g7am60xg76amcyh8q0-r-Rcpp-1.0.12/library"                        
[17] "/nix/store/942q1h7rgi7wdl9g9nl9icrsh1xlgmk4-r-RcppArmadillo-0.12.8.1.0/library"           
[18] "/nix/store/97q5fm6lwn0hzxxfxdl1pw8ks2amch5i-r-rgl-1.3.1/library"                          
[19] "/nix/store/j6vyl4jphvixys5x0ad52njqk4s93wcw-r-base64enc-0.1-3/library"                    
[20] "/nix/store/7m0bajvqhng7dsg5lr1yzkmff9wg8gf9-r-htmltools-0.5.7/library"                    
[21] "/nix/store/cgd4aqg763lp0vvzh9b24ci7dkkzkw6r-r-digest-0.6.35/library"                      
[22] "/nix/store/49rqk71cds9b0fy6qjcpivv0mqivrbf6-r-ellipsis-0.3.2/library"                     
[23] "/nix/store/xz0nk9x7gmgc88xw6wmq6lkppdvxc60j-r-rlang-1.1.3/library"                        
[24] "/nix/store/yriy7b600sqac2crkq6mpk1i41hl9k8y-r-fastmap-1.1.1/library"                      
[25] "/nix/store/69i6h6vnkbdnkfpr96pi9jzrp96g2fnm-r-htmlwidgets-1.6.4/library"                  
[26] "/nix/store/x5whgkl6573w39j9zhraq1090dbk5ag9-r-jsonlite-1.8.8/library"                     
[27] "/nix/store/zka8py06kx4hvmjl5cw17bdfpzqj3k2n-r-knitr-1.45/library"                         
[28] "/nix/store/n2d764m3yvl8qrq7p0ymbi0d09ahvpkw-r-evaluate-0.23/library"                      
[29] "/nix/store/705g6a21mwg4hbcdz89n34xb1jw93lir-r-highr-0.10/library"                         
[30] "/nix/store/0d5ks6cls6ja8izqaydy96pfsnnw6hmz-r-xfun-0.42/library"                          
[31] "/nix/store/mmv11vq65x9d6p6zfwfv78q4x18jy50s-r-yaml-2.3.8/library"                         
[32] "/nix/store/p6g3igq0sym2ndkaz64fqxmxmk19kqs8-r-rmarkdown-2.26/library"                     
[33] "/nix/store/y6yk3q9fydvzih1d51b8wzqr85a9hgnb-r-bslib-0.6.2/library"                        
[34] "/nix/store/263q8ny5sf6y0jln1j42vawrni5yihiw-r-cachem-1.0.8/library"                       
[35] "/nix/store/8n0abpp67f8ygxfh5xncagagimypgvm5-r-jquerylib-0.1.4/library"                    
[36] "/nix/store/g9dbrhl1q2hv40smh9gq242qfd5l5lz6-r-lifecycle-1.0.4/library"                    
[37] "/nix/store/0ckvnrldgdxk2ngx7ppljs5gp7i4ybai-r-cli-3.6.2/library"                          
[38] "/nix/store/d03rnf4js0ch0vn24cbj06w2yyni8dbw-r-glue-1.7.0/library"                         
[39] "/nix/store/x3lh2w2r59n5n471bk07x5jd5pxlxfsw-r-memoise-2.0.1/library"                      
[40] "/nix/store/9wicxxwxl5cy4vq6xavidx5hg33jyfgc-r-mime-0.12/library"                          
[41] "/nix/store/762b9hgq2bgvzf7ym1m2i3gzf9kbjsb2-r-sass-0.4.9/library"                         
[42] "/nix/store/l1aa6fs8kz7q81x8vjav4zd3n2awvnyn-r-fs-1.6.3/library"                           
[43] "/nix/store/j4sgi9whay0ldghkrgascb7i5cxfiy18-r-rappdirs-0.3.3/library"                     
[44] "/nix/store/qlrw9n9rf43mnvldvag5w5y7fzsbwcv9-r-fontawesome-0.5.2/library"                  
[45] "/nix/store/ckvriqfsqk82xf8j3k1036x4a7534pj9-r-tinytex-0.50/library"                       
[46] "/nix/store/wqxsnk1qff2dc23q3lijiz4syzysxcyw-r-magrittr-2.0.3/library"                     
[47] "/nix/store/8jwj3ambqs3j19l0jnw9rwabwkyawibm-r-Rvcg-0.22.2/library"                        
[48] "/nix/store/pha2c9f9vd2lfka2v5aq3lp46pcbarik-r-RcppEigen-0.3.4.0.0/library"                
[49] "/nix/store/5ylipgzwqx1xs6cadrv5wxrjsial7wlr-apple-framework-CoreFoundation-11.0.0/Library"
[50] "/nix/store/mcl9p6myk7dszrij2c1y87qigv5mh17y-R-4.3.3/lib/R/library"

@HVinther what is your libpath? i have had many segmentation faults before on macOS because of linked system libs and permission issues, unfortunately in nix the default is that R_LIBS_USER gets set, which is for your host's R, unless you are using a temporary nix-shell. This is why we have the .Rprofile hack with rix::rix_init() also called in rix::rix(). Unfortunately, rix 12.0.2 suffered from a bug writing empty .Rprofile files. So my suggestion is to check your .libPaths() output and make sure you have the custom .Rprofile.

In the project where I discovered the problem I did indeed generate the default.nix with rix. I do also have a non empty .Rprofile file generated by rix. When calling .libPaths() in a R session in a nix-shell created from that expression I only get paths starting with /nix/store/. In the temporary shell example used to recreate the problem found in my project shell I do get an R folder inside my HOME directory when calling .libPaths(). However this folder is empty.

@HVinther
Copy link
Author

I've now also removed R and all R-packages from my host system. Now when I call .libPaths() from a nix-shell R session only nix/store paths are returned wether from a rix written expression or from a temporary shell. In both cases the graphics issue persists. Ie. either rgl fails to connect to an X11 display if the shell is pure and the XAUTHORITY is unkeept or there is a seqfault on load.

@b-rodrigues
Copy link
Contributor

I guess nixgl is the solution then, on non-NixOS systems. @HVinther can we close this issue?

@HVinther
Copy link
Author

Yes, thank you all for your help and time.

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

No branches or pull requests

5 participants