3

I have an Rstudio project that I've been working on. Since I last updated Rstudio to 1.0.143 - Mac OS X 10.6+ (64-bit) the project fails to start up. I think it might be linked to a package that was automatically loading on start-up and for whatever reason has not decided to stop working with R/Rstudio. XLConnect...

I've tried removing .RData, .Rhistory and .Rproj.user from the directory. Only removing .RData worked and Rstudio started up without issues. I don't seem to have any .RProfile files in the directory, my home directory or a site-wide file either.

Right now I can't even open the Rstudio session because it crashes with an error

R encountered a fatal error. The session was terminated.

I can open other Rstudio sessions without a problem.

When I open a separate R session (no R studio) and try to

load('path/to/.RData')

I get the following error message:

* caught segfault * address 0x18, 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(name)

7: doTryCatch(return(expr), name, parentenv, handler)

8: tryCatchOne(expr, names, parentenv, handlers[[1L]])

9: tryCatchList(expr, classes, parentenv, handlers)

10: tryCatch(loadNamespace(name), error = function(e) { warning(gettextf("namespace %s is not available and has been

replaced\nby .GlobalEnv when processing object %s", sQuote(name)[1L], sQuote(where)), domain = NA, call. = >FALSE, immediate. = TRUE) .GlobalEnv})

11: ..getNamespace(c("openxlsx", "4.0.17"), "uwc.sel.book")

12: load("./Dropbox/OxfordTT2017/DNAextraction_26052017/ColWork2017/Fielddata_04052016/.RData")

Possible actions:

1: abort (with core dump, if enabled)

2: normal R exit

3: exit R without saving workspace

4: exit R saving workspace

So I'm looking for a way to stop the Rstudio session from loading the packages on startup (I'm not sure why it does this in the first place as I don't remember setting any kind of RProfile..).

loki
  • 9,816
  • 7
  • 56
  • 82
user2465805
  • 53
  • 1
  • 7

3 Answers3

5

It seems that you created some objects in previous RStudio seeion, and they need certain packages. When you closed RStudio, your workspace was saved in .RData file. Then if you start that project again, RStudio will try to retore last workspace, but these objects need certain packages to work. So you see that RStudio load those packages at startup.

For example, create a new RStudio project.

install.packages('phylobase')
library(phylobase)
mytree <- phylo4(x=matrix(data=c(4,1, 4,5, 5,2, 5,3, 0,4), ncol=2, byrow=TRUE), tip.label=c("speciesA", "speciesB", "speciesC")) 

Close that project and reopen it (make sure you save workspace).

R version 3.4.1 (2017-06-30) -- "Single Candle"
...
Type 'q()' to quit R.

[Workspace loaded from W:/work/Git/bookdown-minimal/.RData]

Loading required package: phylobase
> search()
 [1] ".GlobalEnv"        "package:phylobase" "tools:rstudio"     "package:stats"     "package:graphics" 
 [6] "package:grDevices" "package:utils"     "package:datasets"  "package:methods"   "Autoloads"        
[11] "package:base" 

mytree is a S4 class object, you can see that phylobase is automatically loaded. You may refer documentation for S4 classes.

Solution

  1. You must install needed packages or give up the .RData file.
  2. You can stop RStudio from loading packages at startup by Tools -> Global Options... uncheck Resotore .RData into workspace at startup. You still can't use the objects in the .RData file unless you do 1.
Zhuoer Dong
  • 629
  • 4
  • 11
  • Do object need packages though? .... I would think to use the object you need the package but surely you don't need to have the package loaded for the object to exist without issues. – user2465805 Jul 19 '17 at 15:11
  • I have already show you an example. You need to recall what packages you have used and install the missed packages. Or you can share your `.RData` file, and I figure out it for you. You may send it to GitHub. – Zhuoer Dong Jul 20 '17 at 14:36
  • Thanks, @gitzhuoer. I don't think openxlsx was the issue... I'm pretty sure R is having issues with the java bit of XLConnect (I've googled the issue and found other people who were having similar problems). I'll add my solution below. – user2465805 Jul 20 '17 at 17:18
  • Congratulations! Since I can't access your `.RData` file, it's hard to figure out which packages go wrong. I just guess **openxlsx** from 11th point of the error message. – Zhuoer Dong Jul 21 '17 at 04:11
2

So this is what I did to solve the problem:

Everything below is at the directory which containes the *.RProj file.

First, I 'hid' the .RData file by running this in the terminal.

mv .RData ./.RData_old

Next, I ran this in an R session (not Rstudio):

remove.packages('XLConnect', 'XLConnectJars')

Then I closed the R session and opened the Rstudio project to make sure it would open fine without the RData file.

After that I got my RData file back

mv .RData_old ./.RData

Finally I opened the project file again and presto!

It complains about packages not installed but at least I know which packages are required. Moreover, my data and results aren't lost.

Zhuoer Dong
  • 629
  • 4
  • 11
user2465805
  • 53
  • 1
  • 7
  • Fortunately, you know which packages might go wrong in this case. But for a general purpose, an empty R environment (without addition packages) is desired. It may be a good idea to share the `.RData` file and ask others' help or install another R. – Zhuoer Dong Jul 21 '17 at 04:25
2

Sharing my solution: In Rstudio, Tools -> Global Option -> General -> uncheck "Restore most recently opened project at startup"

Previously I deleted my .Rprofile, default .Rdata, and unchecked "Restore .RData into workspace at startup" in the Global options. None of these prevented unwanted packages from loading upon starting Rstudio.

I'm now debugging what project might have caused the problem as I wasn't aware a project was being opened.

Not sure if this will have solved your problem, but I found this page trying to debug my problem and no where else did I see to uncheck "Restore most recently opened project at startup".