I have an issue whereby I can load/attach a package when run via R from the terminal but not when run from RStudio Desktop.
I have R-devel (4.3.0; R Under development (unstable) (2023-01-14 r83615)) installed on my MacBook (2015, Intel, Monterey) as I need to use the 'devel' version of Bioconductor (3.17), along with RStudio (Version 2022.12.0+353 (2022.12.0+353)).
The package is a core Bioconductor package, IRanges, which is towards the base of the Bioconductor dependency stack, and so I cannot use many key packages via RStudio.
Here's an illustration of the problem.
When running from R from the terminal (iTerm) everything works as expected:
library(IRanges)
#> Loading required package: BiocGenerics
#>
#> Attaching package: 'BiocGenerics'
#> The following objects are masked from 'package:stats':
#>
#> IQR, mad, sd, var, xtabs
#> The following objects are masked from 'package:base':
#>
#> anyDuplicated, aperm, append, as.data.frame, basename, cbind,
#> colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find,
#> get, grep, grepl, intersect, is.unsorted, lapply, Map, mapply,
#> match, mget, order, paste, pmax, pmax.int, pmin, pmin.int,
#> Position, rank, rbind, Reduce, rownames, sapply, setdiff, sort,
#> table, tapply, union, unique, unsplit, which.max, which.min
#> Loading required package: S4Vectors
#> Loading required package: stats4
#>
#> Attaching package: 'S4Vectors'
#> The following objects are masked from 'package:base':
#>
#> expand.grid, I, unname
IRanges()
#> IRanges object with 0 ranges and 0 metadata columns:
#> start end width
#> <integer> <integer> <integer>
Created on 2023-01-27 with reprex v2.0.2
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R Under development (unstable) (2023-01-14 r83615)
#> os macOS Big Sur ... 10.16
#> system x86_64, darwin17.0
#> ui X11
#> language (EN)
#> collate en_AU.UTF-8
#> ctype en_AU.UTF-8
#> tz Australia/Melbourne
#> date 2023-01-27
#> pandoc 2.18 @ /usr/local/bin/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> BiocGenerics * 0.45.0 2022-11-13 [1] Bioconductor
#> cli 3.6.0 2023-01-09 [1] CRAN (R 4.3.0)
#> digest 0.6.31 2022-12-11 [1] CRAN (R 4.3.0)
#> evaluate 0.20 2023-01-17 [1] CRAN (R 4.3.0)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.3.0)
#> fs 1.6.0 2023-01-23 [1] CRAN (R 4.3.0)
#> glue 1.6.2 2022-02-24 [1] CRAN (R 4.3.0)
#> htmltools 0.5.4 2022-12-07 [1] CRAN (R 4.3.0)
#> IRanges * 2.33.0 2022-11-13 [1] Bioconductor
#> knitr 1.42 2023-01-25 [1] CRAN (R 4.3.0)
#> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.3.0)
#> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.3.0)
#> rlang 1.0.6 2022-09-24 [1] CRAN (R 4.3.0)
#> rmarkdown 2.20 2023-01-19 [1] CRAN (R 4.3.0)
#> S4Vectors * 0.37.3 2022-12-07 [1] Bioconductor
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0)
#> withr 2.5.0 2022-03-03 [1] CRAN (R 4.3.0)
#> xfun 0.36 2022-12-21 [1] CRAN (R 4.3.0)
#> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.3.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.3/Resources/library
#>
#> ──────────────────────────────────────────────────────────────────────────────
However, when I run the same code from RStudio (output copy-pasted from RStudio console because when run via reprex::reprex()
it works as it does when R is run from the terminal) I get the following error:
> library(IRanges)
Loading required package: BiocGenerics
Attaching package: ‘BiocGenerics’
The following objects are masked from ‘package:stats’:
IQR, mad, sd, var, xtabs
The following objects are masked from ‘package:base’:
anyDuplicated, aperm, append, as.data.frame, basename, cbind, colnames, dirname, do.call,
duplicated, eval, evalq, Filter, Find, get, grep, grepl, intersect, is.unsorted, lapply, Map,
mapply, match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank, rbind,
Reduce, rownames, sapply, setdiff, sort, table, tapply, union, unique, unsplit, which.max,
which.min
Loading required package: S4Vectors
Loading required package: stats4
Attaching package: ‘S4Vectors’
The following objects are masked from ‘package:base’:
expand.grid, I, unname
Error: package or namespace load failed for ‘IRanges’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.3/Resources/library/IRanges/libs/IRanges.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.3/Resources/library/IRanges/libs/IRanges.so, 0x0006): Library not loaded: '/Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libR.dylib'
Referenced from: '/Library/Frameworks/R.framework/Versions/4.3/Resources/library/IRanges/libs/IRanges.so'
Reason: tried: '/Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libR.dylib' (no such file), '/usr/local/lib/libR.dylib' (no such file), '/usr/lib/libR.dylib' (no such file)
> IRanges()
Error in IRanges() : could not find function "IRanges"
Created on 2023-01-27 with reprex v2.0.2
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R Under development (unstable) (2023-01-14 r83615)
#> os macOS Monterey 12.6.2
#> system x86_64, darwin17.0
#> ui RStudio
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Australia/Melbourne
#> date 2023-01-27
#> rstudio 2022.12.0+353 Elsbeth Geranium (desktop)
#> pandoc 2.19.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#>
#>─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> BiocGenerics * 0.45.0 2022-11-13 [1] Bioconductor
#> callr 3.7.3 2022-11-02 [1] CRAN (R 4.3.0)
#> cli 3.6.0 2023-01-09 [1] CRAN (R 4.3.0)
#> clipr 0.8.0 2022-02-22 [1] CRAN (R 4.3.0)
#> digest 0.6.31 2022-12-11 [1] CRAN (R 4.3.0)
#> evaluate 0.20 2023-01-17 [1] CRAN (R 4.3.0)
#> fansi 1.0.4 2023-01-22 [1] CRAN (R 4.3.0)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.3.0)
#> fortunes 1.5-4 2016-12-29 [1] CRAN (R 4.3.0)
#> fs 1.6.0 2023-01-23 [1] CRAN (R 4.3.0)
#> glue 1.6.2 2022-02-24 [1] CRAN (R 4.3.0)
#> htmltools 0.5.4 2022-12-07 [1] CRAN (R 4.3.0)
#> knitr 1.42 2023-01-25 [1] CRAN (R 4.3.0)
#> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.3.0)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0)
#> pillar 1.8.1 2022-08-19 [1] CRAN (R 4.3.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0)
#> processx 3.8.0 2022-10-26 [1] CRAN (R 4.3.0)
#> ps 1.7.2 2022-10-26 [1] CRAN (R 4.3.0)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0)
#> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.3.0)
#> rlang 1.0.6 2022-09-24 [1] CRAN (R 4.3.0)
#> rmarkdown 2.20 2023-01-19 [1] CRAN (R 4.3.0)
#> rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.3.0)
#> S4Vectors * 0.37.3 2022-12-07 [1] Bioconductor
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0)
#> tibble 3.1.8 2022-07-22 [1] CRAN (R 4.3.0)
#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.3.0)
#> vctrs 0.5.2 2023-01-23 [1] CRAN (R 4.3.0)
#> withr 2.5.0 2022-03-03 [1] CRAN (R 4.3.0)
#> xfun 0.36 2022-12-21 [1] CRAN (R 4.3.0)
#> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.3.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.3/Resources/library
#>
#>───────────────────────────────────────────────────────────────────────────────────────────────────────────────
The key part of the error message references R 4.2, but I don't currently have that installed (although it would have been some time last year).
# Only R 4.3 is installed
% ls -lhs /Library/Frameworks/R.framework/Versions
total 0
0 drwxrwxr-x 6 root admin 192B 25 Jan 08:20 4.3
0 lrwxrwxr-x 1 root admin 3B 25 Jan 08:20 Current -> 4.3
I'm unsure if related but I did at one point have RSwitch installed but that is no longer the case.
Why is RStudio seemingly picking up a different or somehow broken R installation or package library and how can I fix this so that I get the same behaviour whether R is run from the terminal or via RStudio.
Thanks for your help,
Pete