Stop packages from loading on startup in RStudio - r

When opening RStudio I have a few packages that are loading. I have not set up my .rprofile to load packages on start up.
Here's the content of my current profile:
# startup options for R
# turn off scientific notation by default
# hard code the US repo for CRAN
.First <- function() {
options(scipen = 999)
}
local({
r = getOption("repos")
r["CRAN"] = "https://cran.rstudio.com/"
options(repos = r)
})
For regular start up and most projects, these packages are loading:
Loading required package: RMySQL
Loading required package: DBI
Although, for another project I see this:
Loading required package: RMySQL
Loading required package: DBI
Loading required package: clValid
Loading required package: cluster
At startup, here is what my session looks like:
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/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] RMySQL_0.10.13 DBI_0.7
loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 magrittr_1.5 maps_3.2.0 munsell_0.4.3
[5] colorspace_1.3-2 geosphere_1.5-5 lattice_0.20-35 rjson_0.2.15
[9] jpeg_0.1-8 rlang_0.2.0 stringr_1.3.0 plyr_1.8.4
[13] tools_3.4.1 grid_3.4.1 gtable_0.2.0 png_0.1-7
[17] lazyeval_0.2.0 tibble_1.4.2 ggmap_2.6.1 mapproj_1.2-5
[21] reshape2_1.4.2 ggplot2_2.2.1 ggrepel_0.6.5 sp_1.2-5
[25] stringi_1.1.6 compiler_3.4.1 pillar_1.1.0.9000 RgoogleMaps_1.4.1
[29] scales_0.5.0 proto_1.0.0

Apparently I had prior established database connection objects that were saved in my .Rdata file and upon loading of a project these connections were requiring the packages to be loaded. After removing the connections the packages no longer load on start up.

Related

Use older version of ggplot in R script file

I have ggplot2 3.4.0 installed on Ubuntu 22.04, but for some reasons I would like to use older version ggplot2 3.3.6.
library(ggplot2, lib.loc="~/R/ggplot336/")
I worked fine when I started with a clean script file. However, when I use an existing script file like:
library(ggplot2, lib.loc="~/R/ggplot336/")
ggimage::geom_image()
I got the following error massage:
Error in value[3L] :
Package ‘ggplot2’ version 3.4.0 cannot be unloaded:
Error in unloadNamespace(package) : namespace ‘ggplot2’ is imported by ‘ggfun’, ‘ggplotify’, ‘ggimage’ so cannot be unloaded
Edit
Fresh start Rstudio
Open my R script file with following 3 lines:
sessionInfo()
library(ggplot2, lib.loc="~/R/ggplot336/")
ggimage::geom_image()
When I run the first line, sessionInfo() before doing anything else. We can see ggplot2_3.4.0 there. Could this be a Rstudio feature or an issue?
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
locale:
[1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C LC_TIME=en_AU.UTF-8
[4] LC_COLLATE=en_AU.UTF-8 LC_MONETARY=en_AU.UTF-8 LC_MESSAGES=en_AU.UTF-8
[7] LC_PAPER=en_AU.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 highr_0.9 pillar_1.8.1 compiler_4.2.2
[5] R.utils_2.12.2 R.methodsS3_1.8.2 yulab.utils_0.0.5 tools_4.2.2
[9] digest_0.6.30 evaluate_0.18 jsonlite_1.8.3 lifecycle_1.0.3
[13] tibble_3.1.8 gtable_0.3.1 ggimage_0.3.1 R.cache_0.16.0
[17] pkgconfig_2.0.3 rlang_1.0.6 reprex_2.0.2 DBI_1.1.3
[21] cli_3.4.1 ggplotify_0.1.0 rstudioapi_0.14 magick_2.7.3
[25] yaml_2.3.6 xfun_0.35 fastmap_1.1.0 knitr_1.41
[29] withr_2.5.0 dplyr_1.0.10 styler_1.8.1 generics_0.1.3
[33] vctrs_0.5.1 fs_1.5.2 gridGraphics_0.5-1 grid_4.2.2
[37] tidyselect_1.2.0 glue_1.6.2 R6_2.5.1 processx_3.8.0
[41] fansi_1.0.3 rmarkdown_2.18 clipr_0.8.0 callr_3.7.3
[45] ggplot2_3.4.0 purrr_0.3.5 magrittr_2.0.3 ps_1.7.2
[49] htmltools_0.5.3 scales_1.2.1 assertthat_0.2.1 colorspace_2.0-3
[53] utf8_1.2.2 munsell_0.5.0 ggfun_0.0.9 R.oo_1.25.0
It looks like R studio is loading in all of the previous libraries from a previous session. Maybe something leftover in .RData or .Rhistory. A fresh start of R should have far few loaded libraries.
Here is my fresh start:
sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.6.1
Matrix products: default
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
loaded via a namespace (and not attached):
[1] compiler_4.2.2 tools_4.2.2
In Rstudio's preference you should see this screen:
I would try unchecking all of the boxes and then quit and restart Rstudio to see if that clears up the problem.
After some experiments, I kind of worked out the problem. Since this has consumed so much time of my time, I thought this could be helpful to others.
The problem is :: (double colon) with packages using ggplot2, such as ggimage in my example. It appears that RStudio automatically load some dependent packages when a script file is open. One way to fix this problem for my work now is to remove ::, but use library() then function (geom_image) instead.
This fixed my problem but I still don't understand why RStudio behaves this way.
If :: (double colon) is necessary, comment lines containing ::, then after loading older version of ggplot2, uncomment those lines. A little awkward, but it works for me.

GenomicRanges Error loading DESeq2 library on R

I tried to loading DESeq2 on R:
library(DESeq2)
The Error showed is:
Loading required package: GenomicRanges
Error: package or namespace load failed for ‘GenomicRanges’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
object 'vI' not found
Error: package ‘GenomicRanges’ could not be loaded
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/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] parallel stats4 stats graphics grDevices utils datasets
[8] methods base
other attached packages:
[1] GenomeInfoDb_1.22.1 IRanges_2.21.8 S4Vectors_0.25.15
[4] BiocGenerics_0.32.0
loaded via a namespace (and not attached):
[1] rstudioapi_0.11 zlibbioc_1.32.0 R6_2.4.1
[4] fansi_0.4.1 tools_3.6.3 pkgbuild_1.0.6
[7] cli_2.0.2 withr_2.1.2 remotes_2.1.1
[10] assertthat_0.2.1 rprojroot_1.3-2 crayon_1.3.4
[13] processx_3.4.2 GenomeInfoDbData_1.2.2 BiocManager_1.30.10
[16] callr_3.4.3 bitops_1.0-6 ps_1.3.2
[19] RCurl_1.98-1.1 curl_4.3 glue_1.4.0
[22] compiler_3.6.3 backports_1.1.6 prettyunits_1.1.1
I blocked since 2 days. All the problem start for "S4Vectors" package. I solved it. I update the R. I donwloaded and manually put in the library r folder the "XVector" version ‘0.27.2’ as required from GenomicRanges.
I need to use DESeq2 to normalize my cont data. I open to use also something different from r
At the end, I fixed the problem uninstalled and re-installed all the R library from my PC keeping the same OS and R version. I continue to ignore the real identity of the problem.
I resolved this problem simply by removing the "GenomicRanges" and "IRange" packages and installing "GenomicRanges" again.
To remove these packages I used .libPaths() to find the library path and removed GenomicRanges" and "IRange" folders.

error "object ‘coef.cv.glmnet’ is not exported by 'namespace:glmnet' " while loading Lime package in R -

I've successfully installed Lime (and glmnet) in R but when I try loading it i receive an error:
> require(lime)
Loading required package: lime
Error: package or namespace load failed for ‘lime’:
object ‘coef.cv.glmnet’ is not exported by 'namespace:glmnet'
Searched online and can't seem to find a solution for this.
This is my sessioninfo()
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)
Matrix products: default
locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] glmnet_3.0 Matrix_1.2-17
loaded via a namespace (and not attached):
[1] Rcpp_1.0.3 rstudioapi_0.10 magrittr_1.5 tidyselect_0.2.5 munsell_0.5.0 colorspace_1.4-1 lattice_0.20-38 R6_2.4.0 rlang_0.4.1
[10] foreach_1.4.7 dplyr_0.8.3 tools_3.6.1 grid_3.6.1 gtable_0.3.0 iterators_1.0.12 lazyeval_0.2.2 assertthat_0.2.1 tibble_2.1.3
[19] crayon_1.3.4 purrr_0.3.3 ggplot2_3.2.1 codetools_0.2-16 shape_1.4.4 glue_1.3.1 compiler_3.6.1 pillar_1.4.2 scales_1.0.0
[28] pkgconfig_2.0.3
I've updated all my packages.
glmnet loads successfully
> library(glmnet)
Loaded glmnet 3.0
The recent major update of glmnet (which now does not export coef.cv.glmnet anymore) appears to have broken lime. You can see errors with the same cause in the CRAN tests. You can expect a fix by the package maintainer soon (or the package will be archived by CRAN). See also this bug report and the answer by the maintainer:
This is due to a recent breaking change in glmnet—lime will be updated soon to fix this

Error in loading package SASxport: object ‘label<-.data.frame’ is not exported by 'namespace:Hmisc'

I'm trying to read data in the XPT format into R (the format can be found for example in the NHANES data). I found two functions doing this:
library("Hmisc")
sasxport.get("C:/path/file.XPT")
and
library("SASxport")
read.xport("C:/path/file.XPT")
The sasxport.get works, so I'm basically fine, but still inquisitive enough to understand (and solve) the following error: after the installation of the SASxport package, I cannot load it. When I run library("SASxport"), I get the error message:
Error: package or namespace load failed for ‘SASxport’:
object ‘label<-.data.frame’ is not exported by 'namespace:Hmisc'
Adopting this suggestion, I also ran
remove.packages(c("SASxport", "Hmisc"))
install.packages('Hmisc', dependencies = TRUE)
install.packages('SASxport', dependencies = TRUE)
what did not change the error message.
This is my sessionInfo():
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Hmisc_4.1-1 ggplot2_2.2.1 Formula_1.2-2 survival_2.41-3 lattice_0.20-35
loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 pillar_1.0.1 compiler_3.4.3 RColorBrewer_1.1-2 plyr_1.8.4
[6] base64enc_0.1-3 iterators_1.0.9 tools_3.4.3 rpart_4.1-11 digest_0.6.13
[11] tibble_1.4.1 gtable_0.2.0 htmlTable_1.11.1 checkmate_1.8.5 rlang_0.1.6
[16] icenReg_2.0.7 Matrix_1.2-12 foreach_1.4.4 rstudioapi_0.7 yaml_2.1.16
[21] gridExtra_2.3 coda_0.19-1 stringr_1.2.0 cluster_2.0.6 knitr_1.18
[26] htmlwidgets_0.9 grid_3.4.3 nnet_7.3-12 data.table_1.10.4-3 foreign_0.8-69
[31] latticeExtra_0.6-28 magrittr_1.5 scales_0.5.0 backports_1.1.2 codetools_0.2-15
[36] htmltools_0.3.6 splines_3.4.3 colorspace_1.3-2 stringi_1.1.6 acepack_1.4.1
[41] lazyeval_0.2.1 munsell_0.4.3
The last update of SASxport happend nearly two years ago (2016-03-11). So the Hmisc package it imports might have changed in the meantime. Looking up the Hmisc archive I found the version number on 2016-03-11 to be 3.17-2. So installing this version fixes the problem:
library("devtools")
install_version("Hmisc", version = "3.17-2")
Two reasons speak against using SASxport in this case:
You need to use a old version of a package which might happer your work in later steps.
SASxport needs Hmisc for a task that Hmisc can do already by itself, so SASxport is expendable when reading in XPT files.

CRAN notes that files cannot be checked without ‘pandoc’ being installed

In doing final checks on a CRAN package submission, this NOTE comes up:
* checking top-level files ... NOTE
Files ‘README.md’ or ‘NEWS.md’ cannot be checked without ‘pandoc’ being installed.
However, pandoc is definitely installed as I use it regularly, and this package makes frequent use of it in documentation using pkgdown.
> rmarkdown::pandoc_available()
[1] TRUE
> rmarkdown::pandoc_version()
[1] ‘1.19.2.1’
I want to avoid installing pandoc from source because the latest version of pandoc supercedes the version installed with other R packages and causes weird output.
There is a similar question from a few years back but the solutions there are to either:
Install pandoc from source or via the installr package, whereas I already have pandoc installed; and,
Place the two files into .Rbuildignore, however both should be accepted with CRAN submissions now.
This note only comes up when checked using devtools::release() and when using devtools::check(check_version = TRUE), which otherwise passes with no warnings or notes.
The RStudio install of Pandoc:
Sys.getenv('RSTUDIO_PANDOC')
[1] "/Applications/RStudio.app/Contents/MacOS/pandoc"
Which I had previously exported to my ~/.bash_profile:
export PATH="$PATH:/Applications/Rstudio.app/Contents/MacOS/pandoc"
Any ideas?
> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.2
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] cancensus_0.1.6
loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 rstudioapi_0.7 knitr_1.17 bindr_0.1
[5] xml2_1.1.1 magrittr_1.5 roxygen2_6.0.1 devtools_1.13.4
[9] R6_2.2.2 rlang_0.1.6 httr_1.3.1 stringr_1.2.0
[13] dplyr_0.7.4 tools_3.4.3 hunspell_2.9 git2r_0.20.0
[17] withr_2.1.1 htmltools_0.3.6 rversions_1.0.3 commonmark_1.4
[21] rprojroot_1.2 yaml_2.1.14 digest_0.6.13 assertthat_0.2.0
[25] tibble_1.3.4 crayon_1.3.4 bindrcpp_0.2 curl_3.1
[29] evaluate_0.10.1 memoise_1.1.0 glue_1.2.0 rmarkdown_1.8
[33] stringi_1.1.5 compiler_3.4.3 backports_1.1.0 desc_1.1.1
[37] jsonlite_1.5 pkgconfig_2.0.1
This happens because devtools::release calls devtools::check with check_version = TRUE.
You can also run devtools::check(check_version = TRUE) to trigger the same note.
I think for this part you would need pandoc on your PATH.
(indeed, after adding the existing ...\RStudio\bin\pandoc to my PATH the note is gone)
This question appears to be a duplicate.
Currently no accepted solution at the above linked Q. However, #hrbrmster's suggested solution in that thread: adding the README.md and NEWS.md to the .Rbuildignore remove the NOTES for me.
Current .RBuildignore contents
^pkg_name_here\.Rproj$
^\.Rproj\.user$
^cran-comments\.md$
^CODE_OF_CONDUCT\.md$
^README\.md$
^NEWS\.md$

Resources