Why is R crashing when I try to import certain packages? - r

Anytime I have tried to import a package in R, it ends up crashing. To illustrate, if I run a command such as library(broom) in my terminal, the following error is yielded:
*** caught segfault ***
address 0x18, cause 'memory not mapped'
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(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]])
6: namespaceImport(ns, loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]), from = package)
7: loadNamespace(package, lib.loc)
8: doTryCatch(return(expr), name, parentenv, handler)
9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
10: tryCatchList(expr, classes, parentenv, handlers)
11: tryCatch({ attr(package, "LibPath") <- which.lib.loc ns <- loadNamespace(package, lib.loc) env <- attachNamespace(ns, pos = pos, deps)}, 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) message(paste("Error:", msg), domain = NA) else stop(msg, call. = FALSE, domain = NA)})
12: library(broom)
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
This error is followed by my R crashing in my terminal. Furthermore, this result replicated within RStudio, and the whole program must be reopened if I try to import packages. Interestingly, not all packages behave the same way. When I import a basic package such as library(stats) or library(base), it works fine.
I have tried to uninstall R, Rstudio, and relevant R packages from my computer and then reinstall them (as per https://support.rstudio.com/hc/en-us/community/posts/115007714568-Latest-version-of-Rstudio-rmarkdown-causing-abort-on-R-version-3-4-0-for-x86-64-apple-darwin15-6-0-64-bit-), but with no success. Is this a problem that is related to the setup of my PATH variable?
For the record, I am running R-3.4 on Mac OSX-10.12 Sierra.
UPDATE
This might not be that important, but I decided to look around and see where my packages were installed by putting them all in a dataframe in R (ip<-as.data.frame(installed.packages())), and I noticed that my packages are stored in two different file paths– either /Users/bob/Library/R/3.4/library, or /Library/Frameworks/R.framework/Versions/3.4/Resources/library. Does anybody think this discrepancy is the cause for my R crashing all the time?

After figuring out that I had installed packages downloaded to two different libraries (see Update section in question above), I decided to remove all packages that I had installed. Using this source (https://www.r-bloggers.com/how-to-remove-all-user-installed-packages-in-r/) as my guide, I carried out the following commands:
ip <- as.data.frame(installed.packages())
ip <- ip[!(ip[,"Priority"] %in% c("base", "recommended")),]
ip <- subset(ip, !grepl("MRO", ip$LibPath))
path.lib <- unique(ip$LibPath)
pkgs.to.remove <- ip[,1]
sapply(pkgs.to.remove, remove.packages, lib = path.lib)
Furthermore, I also removed any remaining packages in the folder Users/bob/Library/R/3.4/library, and then I set only one of my libraries as the default library where installed packages were downloaded to:
.libPaths("/Library/Frameworks/R.framework/Versions/3.4/Resources/library")
And then ran .libPaths() again to make sure that this file path was the first that got printed. I then carried out install.packages("NameOfDesiredPackage") on any of the packages I wanted, and when I imported them into my console or terminal, they imported with no problem.

Related

Why can't install tidymodels package in Jupyter notebook?

My Rstudio is 4.0.4 version, however, it showed that the package was built under R verision 3.6.3.
And I can not use this package. How to solove this problem?
library(tidymodels)
Warning message:
"package 'tidymodels' was built under R version 3.6.3"
Error: package or namespace load failed for 'tidymodels' in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
namespace 'recipes' 0.1.5 is being loaded, but >= 0.1.16 is required
Traceback:
1. library(tidymodels)
2. 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)
. message(paste("Error:", msg), domain = NA)
. else stop(msg, call. = FALSE, domain = NA)
. })
3. tryCatchList(expr, classes, parentenv, handlers)
4. tryCatchOne(expr, names, parentenv, handlers[[1L]])
5. value[[3L]](cond)
6. stop(msg, call. = FALSE, domain = NA)
That's a warning. The actual error shows beneath:
Error: package or namespace load failed for 'tidymodels' in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
namespace 'recipes' 0.1.5 is being loaded, but >= 0.1.16 is required
And it is very clear: you need a more recent version of recipes which you can get through install.packages. It could be that a newer version of the package is not available for your R version, in which case you'll need to install RTools (assuming windows, otherwise not required) and do an installation from source.

macOS fresh install of R - devtools are giving segfault error -

I've done a fresh reinstall of R 3.6 on a macOS Mojava v 10.14.6
I've install clang 7 here from the provided installer /usr/local/clang7
I have xcode
But there's something wrong with the install that I can seem to figure out
.libPaths()
[1] "/Users/annaleigh/Library/R/3.6/library"
[2] "/Library/Frameworks/R.framework/Versions/3.6/Resources/library"
> install.packages("devtools")
Installing package into ‘/Users/annaleigh/Library/R/3.6/library’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/bin/macosx/el-capitan/contrib/3.6/devtools_2.2.1.tgz'
Content type 'application/x-gzip' length 339075 bytes (331 KB)
==================================================
downloaded 331 KB
The downloaded binary packages are in
/var/folders/xr/lmkkh0p10t948k1n104z1jsh0000gn/T//Rtmpf54J79/downloaded_packages
> library(devtools)
\Loading required package: usethis
*** caught segfault ***
address 0x2c2e0, cause 'memory not mapped'
However the usethis library seem to load fine
> library(usethis)
> library(devtools)
*** caught segfault ***
address 0x2c2e0, cause 'memory not mapped'
Traceback:
1: dyn.load(file, DLLpath = DLLpath, ...)
2: library.dynam(lib, package, package.lib)
3: loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]])
4: asNamespace(ns)
5: namespaceImportFrom(ns, loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]), i[[2L]], from = package)
6: loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]])
7: asNamespace(ns)
8: namespaceImportFrom(ns, loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]), i[[2L]], from = package)
9: loadNamespace(package, lib.loc)
10: doTryCatch(return(expr), name, parentenv, handler)
11: tryCatchOne(expr, names, parentenv, handlers[[1L]])
12: tryCatchList(expr, classes, parentenv, handlers)
13: 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) message(paste("Error:", msg), domain = NA) else stop(msg, call. = FALSE, domain = NA)})
14: library(devtools)
Answer found here:
https://github.com/r-lib/devtools/issues/1292
"Finally looked at .libPath() and realized that both instances of R were looking at the user library before the system library. So if the packages were linked to different system libraries from the compiled versions (OS X Sierra and El Capitan in my case) this could create the seg fault.
Removing libraries in the user library ~/user/Library/R/version# fixed the issue (with installing to different locations)"

segfault 'memory not mapped' error loading 'ape' in R 3.4

I'm getting two different error messages when attempting to load packages using the 'require' or 'library' functions in R 3.4.1. Since the problem has started, I've only been able to load one package (ggplot2), while others (including any phylogenetics-oriented package, e.g. ape) cause the following error:
*** caught segfault ***
address 0x0, cause 'memory not mapped'
Traceback:
1: getDLLRegisteredRoutines.DLLInfo(dll, addNames = FALSE)
2: assignNativeRoutines(dlls[[lib]], lib, env, nsInfo$nativeRoutines[[lib]])
3: loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]])
4: asNamespace(ns)
5: namespaceImportFrom(ns, loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]), i[[2L]], from = package)
6: loadNamespace(package, lib.loc)
7: doTryCatch(return(expr), name, parentenv, handler)
8: tryCatchOne(expr, names, parentenv, handlers[[1L]])
9: tryCatchList(expr, classes, parentenv, handlers)
10: tryCatch({ attr(package, "LibPath") <- which.lib.loc ns <- loadNamespace(package, lib.loc) env <- attachNamespace(ns, pos = pos, deps)}, 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) message(paste("Error:", msg), domain = NA) else stop(msg, call. = FALSE, domain = NA)})
11: library(ape)
Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
[EDIT: The following error was resolved, see first comment below] When I try to load the package rJava, I get the following error. Other packages that give similar errors:
library(rJava)
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Users/dummyname/R_libs/rJava/libs/rJava.so':
dlopen(/Users/dummyname/R_libs/rJava/libs/rJava.so, 6): Library not loaded: #rpath/libjvm.dylib
Referenced from: /Users/dummyname/R_libs/rJava/libs/rJava.so
Reason: image not found
I've tried uninstalling all packages, as suggested here:
caught segfault error in R
I also re-installed R. The same error appears after reinstalling packages. Session info is below the error message. Suggestions?
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.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
loaded via a namespace (and not attached):
[1] compiler_3.4.1

ggplot2 causing segfault on Mac

There are several reports for this issue all dating 2 to 3 years back:
caught segfault error in R
Problems loading packages (ie. ggplot2) on R 3.2.2 caught segfault address 0x18, cause 'memory not mapped' [duplicate]
Most of them are referring to older system versions and older ggplot2 version. I'm wondering if anybody found alternative solution to the suggested R re-installation (which apparently did not work for everyone)?
I'm on Mac 10.11.6 and when trying to install ggplot2 either from within or outside of R (R CMD INSTALL) I get segfault:
*** caught segfault ***
address 0x18, cause 'memory not mapped'
The same can be reproduced using ggplot2 versions:
1.0.0, 1.0.1, 2.0.0, 2.1.0, 2.2.0
I tested that on fresh R-3.3.2 session. The error occurs during installation, not during loading.
Traceback received:
Traceback:
1: dyn.load(file, DLLpath = DLLpath, ...)
2: library.dynam(lib, package, package.lib)
3: loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]])
4: asNamespace(ns)
5: namespaceImportFrom(ns, loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]), i[[2L]], from = package)
6: loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]])
7: namespaceImport(ns, loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]), from = package)
8: loadNamespace(package, lib.loc, keep.source, partial = TRUE)
9: withCallingHandlers(expr, packageStartupMessage = function(c) invokeRestart("muffleMessage"))
10: suppressPackageStartupMessages(loadNamespace(package, lib.loc, keep.source, partial = TRUE))
11: code2LazyLoadDB(package, lib.loc = lib.loc, keep.source = keep.source, compress = compress)
12: makeLazyLoading(pkg_name, lib, keep.source = keep.source)
13: doTryCatch(return(expr), name, parentenv, handler)
14: tryCatchOne(expr, names, parentenv, handlers[[1L]])
15: tryCatchList(expr, classes, parentenv, handlers)
16: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call)[1L] prefix <- paste("Error in", dcall, ": ") LONG <- 75L msg <- conditionMessage(e) sm <- strsplit(msg, "\n")[[1L]] w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b") if (w > LONG) prefix <- paste0(prefix, "\n ") } else prefix <- "Error : " msg <- paste0(prefix, conditionMessage(e), "\n") .Internal(seterrmessage(msg[1L])) if (!silent && identical(getOption("show.error.messages"), TRUE)) { cat(msg, file = stderr()) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))})
17: try({ suppressPackageStartupMessages(.getRequiredPackages(quietly = TRUE)) makeLazyLoading(pkg_name, lib, keep.source = keep.source)})
18: do_install_source(pkg_name, instdir, pkg, desc)
19: do_install(pkg)
20: tools:::.install_packages()
An irrecoverable exception occurred. R is aborting now ...
/Users/username/miniconda3/lib/R/bin/INSTALL: line 34: 2049 Done echo 'tools:::.install_packages()'
2050 Segmentation fault: 11 | R_DEFAULT_PACKAGES= LC_COLLATE=C "${R_HOME}/bin/R" $myArgs --slave --args ${args}
The reproduce, start new R session and install 'ggplot2' with:
$ R
> install.packages('ggplot2')
Session info:
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin11.4.2 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
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
Any suggestions would be appreciated.

Error with ggplot2 after installing new R

I wanted to install a new version of R.
I downloaded R-3.1.0.pkg and installed it.
I mved my packages from ~/Library/R/3.0 to ~/Library/R/3.1
the new R starts, but when I try to load some packages, I get an error.
This seems to be due to ggplot2. As I can load any package that doesn't depend on ggplot2.
I just reinstalled ggplot2 using install.packges(), but still no luck. R just crashes when I try to load the library.
I performed update.packages(). Is this related to how I migrated my packages?
Also, I seem to have packages in multiple places. Although I think RStudio seems to install all of them in the ~/Library/Frameworks/R.framework/Versions/3.1/Resources/library
thanks
> library(Hmisc)
Loading required package: grid
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2
*** caught segfault ***
address 0x18, cause 'memory not mapped'
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, c(which.lib.loc, lib.loc))
6: doTryCatch(return(expr), name, parentenv, handler)
7: tryCatchOne(expr, names, parentenv, handlers[[1L]])
8: tryCatchList(expr, classes, parentenv, handlers)
9: tryCatch(expr, error = function(e) { call <- conditionCall(e) if (!is.null(call)) { if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L) dcall <- deparse(call)[1L] prefix <- paste("Error in", dcall, ": ") LONG <- 75L msg <- conditionMessage(e) sm <- strsplit(msg, "\n")[[1L]] w <- 14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") if (is.na(w)) w <- 14L + nchar(dcall, type = "b") + nchar(sm[1L], type = "b") if (w > LONG) prefix <- paste0(prefix, "\n ") } else prefix <- "Error : " msg <- paste0(prefix, conditionMessage(e), "\n") .Internal(seterrmessage(msg[1L])) if (!silent && identical(getOption("show.error.messages"), TRUE)) { cat(msg, file = stderr()) .Internal(printDeferredWarnings()) } invisible(structure(msg, class = "try-error", condition = e))})
10: try({ ns <- loadNamespace(package, c(which.lib.loc, lib.loc)) env <- attachNamespace(ns, pos = pos, deps)})
11: library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc)
12: .getRequiredPackages2(pkgInfo, quietly = quietly)
13: library(Hmisc

Resources