3

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?

Bob McBobson
  • 743
  • 1
  • 9
  • 29
  • Might be relevant: https://github.com/tidyverse/dplyr/issues/322 – Eric Watt Sep 19 '17 at 17:10
  • @EricWatt Sadly none of the approaches offered in that thread have made any impact. I have tried editing my Makevars file in the .R folder, and also tried running `devtools::install_github("caret", build_vignettes=FALSE)`, but that caused R to crash almost instantaneously. – Bob McBobson Sep 20 '17 at 09:54

1 Answers1

2

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.

Bob McBobson
  • 743
  • 1
  • 9
  • 29
  • Thank you. Another problem I had in addition to the ones you mentioned above was that some packages were installed in two locations. (Not sure how that came about, but it's fixed now.) – Sarah Messer Mar 15 '18 at 21:31