ggplot2: Error message that I can't understand - r

I have a data frame "df1" of the following kind:
set.seed(2)
df1 = data.frame(Var1=rep(c('a','b','c','d'),3),
Var2=rep(c('aa','bb','cc'),each=4),
value=rnorm(12))
I try to create this plot:
ggplot(df1) + geom_bar(aes(x=Var2,y=value),stat="identity") + facet_wrap(~Var1)
and I get the following error message that I don't understand:
formal classes cannot be used without the methods package
What's wrong ? I can't find a package called methods by the way.
Here is my sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] fr_CH.UTF-8/fr_CH.UTF-8/fr_CH.UTF-8/C/fr_CH.UTF-8/fr_CH.UTF-8
attached base packages:
[1] utils graphics methods stats base
other attached packages:
[1] agricolae_1.1-4 reshape2_1.2.2 lattice_0.20-15 ggplot2_0.9.3.1 data.table_1.8.8
loaded via a namespace (and not attached):
[1] colorspace_1.2-2 datasets_3.0.1 dichromat_2.0-0 digest_0.6.3 grDevices_3.0.1 grid_3.0.1 gtable_0.1.2
[8] labeling_0.1 lme4_0.999999-2 MASS_7.3-26 Matrix_1.0-12 munsell_0.4 nlme_3.1-109 plyr_1.8
[15] proto_0.3-10 RColorBrewer_1.0-5 scales_0.2.3 stats4_3.0.1 stringr_0.6.2 tools_3.0.1
Thank you

I encountered the same error message and found a solution but in a different context.
The error happened while running an R script on a cluster. Interestingly the same script worked fine on a laptop (during testing with a subset of the data).
The solution in my context was to import the package with which the data was preprocessed. What I mean is that I previously saved an RDS file created using the package "Seurat". When reading the RDS file in a new session the package "Seurat" would load automatically when ran on a local machine. However on the cluster I had to specifically load the package with the library() command, before reading the RDS file. This is what solved the problem and stopped the obfuscated error message.

Related

Cannot load package in R

Since yesterday, I cannot load some common used packages, e.g. reshape2 and stringr through library command.
Step to reproduce my problem:
1) Start a new session in Rstudio server (Version 0.99.467). I also kill the active-sessions in Rstudio server.
2) Run these codes
library(ggplot2)
library(stringr)
3) Get an error message:
Error in unloadNamespace(package) :
namespace ‘stringr’ is imported by ‘reshape2’ so cannot be unloaded
Show Traceback
Rerun with Debug
Error in library(stringr) : “stringr” version 0.6.2 cannot be unloaded.
But I don't get error if stringr is loaded before ggplot2. How should I fix this problem. Thanks for any suggestions.
I may have to update R to 3.2
My R session info:
R version 3.1.3 (2015-03-09)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu precise (12.04.5 LTS)
locale:
[1] LC_CTYPE=en_AU.UTF-8 LC_NUMERIC=C LC_TIME=en_AU.UTF-8 LC_COLLATE=en_AU.UTF-8
[5] LC_MONETARY=en_AU.UTF-8 LC_MESSAGES=en_AU.UTF-8 LC_PAPER=en_AU.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_1.0.0
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 digest_0.6.4 grid_3.1.3 gtable_0.1.2 MASS_7.3-39 munsell_0.4.2 plyr_1.8.1
[8] proto_0.3-10 Rcpp_0.11.2 reshape2_1.4 scales_0.2.4 stringr_0.6.2 tools_3.1.3
I resolved my problem through updating R and all R packages.
I guess the problem is caused by old version of stringr or reshape2 as I install the same packages in different places (system folder or personal library). R tried to load a old version of package.
Even though it is a good practice to update R for me it was not necessary to solve the same issue. The problem can result from few .libPaths(). With .libPaths("C:/Program Files/R/R-3.4.3patched/library") you can point out one folder. After that just reinstall of packages, and it should work.
My code:
> .libPaths()
[1] "L:/My Documents/R/win-library/3.4" "C:/Program Files/R/R-3.4.3patched/library"
> .libPaths("C:/Program Files/R/R-3.4.3patched/library")
> packages<-c('ggplot2','data.table','knitr','xtable')
> install.packages(packages)
> lapply(packages,library,character.only=T)
Even though the issue is solved I hope it will help someone.

pander $add function not working

I was able to use pander successfully this morning on one computer, but now I am trying to do it on my own computer, and I am having some weird issues.
Here is my very elementary R Pander code:
library("pander")
library("knitr")
test<-Pandoc$new("My Name","Test")
test$add.paragraph('# Welcome to Test')
test$add.paragraph('*****')
#works so far but here it won't work
test$add(3+3)
#here I get error in dev.control(displaylist = "enable"):
# dev.control() called without an open grpahics device
# In addition: Warning message:
#In png("plots/....png", width=480,height=480,res=72, : failed to load cairo DLL
I literally can't use $add to add R code, and I don't understand why. I would greatly appreciate if someone could help.
Regards
edit:
R version 3.2.1 (2015-06-18)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.4 (Yosemite)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.10.5 rmarkdown_0.7 rapport_0.51 yaml_2.1.13 plyr_1.8.3 lattice_0.20-33 pander_0.5.2 brew_1.0-6
loaded via a namespace (and not attached):
[1] htmltools_0.2.6 tools_3.2.1 Rcpp_0.12.0 reshape_0.8.5 grid_3.2.1 digest_0.6.8
It appears I did not have XQuartz installed. I installed it and everything works so thank you and köszönöm for the help.

R pgirmess alternative for kruskalmc with Kruskal-Wallis rank sum test

I'm trying to run the krushkalmc method after running kruskal.test as part of my analysis with the Kruskal-Wallis rank sum test.
However, I've run into difficulties trying to install the pgirmess package that contains krushkalmc.
trying to install it from inside R:
install.packages("pgirmess")
package ‘pgirmess’ is available as a source package but not as a binary
so then I downloaded it and tried to install it manually:
install.packages("pgirmess", repos = NULL, type="source")
Warning: invalid package ‘pgirmess’
Error: ERROR: no packages specified
Warning in install.packages :
installation of package ‘pgirmess’ had non-zero exit status
and here is my sessionInfo()
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
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
[7] base
other attached packages:
[1] ggplot2_1.0.0
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 digest_0.6.8 grid_3.1.2
[4] gtable_0.1.2 labeling_0.3 MASS_7.3-35
[7] munsell_0.4.2 plyr_1.8.1 proto_0.3-10
[10] Rcpp_0.11.4 reshape2_1.4.1 scales_0.2.4
[13] stringr_0.6.2 tools_3.1.2
I've tried to determine if any other package has the kruskalmc but don't see any.
Do you have any recommendations on a replacement package that I can use that has a test to dive deeper into the results of Kruskal-Wallis rank sum test?
Is there a debug mode on an install.packages to see what might be the problem?
Thanks for your help
I am moving this question over to cross-validated (aka stats.stackoverflow.com) as it is probably a more suitable location for this question. I don't think I have the ability to actually close it here, though. Thanks

Unlink function causing an error for consequent `?` and `plot` functions

I am using tempdir function to create a temporary directory where I extract .zip files with unzip function. In connection with this, I thought it's good to remove the temporary directories to avoid filling my computer up with scrap data. For this purpose I have been using unlink function. Using unlink function before ? or plot functions causes an error on my computer (OS X Mavericks). I have not tested whether this is the case for other operating systems. I did some googling and one theory for similar error message was that this problem could be related to encrypted hard disc. My hard disc is encrypted, so that could match. But I do not understand why should that matter as plot or ? functions should not be related to unlink operation in my mind. Here is an example:
location <- tempdir()
?plot
#works
unlink(location, recursive = TRUE)
?plot
# Error in file(out, "wt") : cannot open the connection
Plotting works with a warning in R and does not work in R Studio:
plot(1:10)
# Warning message:
# In file(out, "wt") :
# cannot open file #'/var/folders/wh/y62s7qxn29s2lvlx1nh9nxpr0000gq/T//RtmpdYlFVc/Rhttpd175551e9e35fa': No such file or # directory
This seems to work in R studio, but not in R:
graphics.off()
?plot
# works again
plot(1:10)
# this works now too
What is going on here? If the problem is related to my encrypted hard disc, is there a neater way extracting .zip files without generating scrap data?
PS. Here is my session information (I had the same problem with R version 3.0.2):
sessionInfo()
R version 3.0.3 (2014-03-06)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
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] grDevices datasets splines grid utils graphics stats methods base
other attached packages:
[1] devtools_1.4.1 roxygen2_3.0.0 gridExtra_0.9.1 data.table_1.8.10 xlsx_0.5.5 xlsxjars_0.5.0 rJava_0.9-6
[8] reshape2_1.2.2 ggplot2_0.9.3.1 plyr_1.8 Hmisc_3.13-0 Formula_1.1-1 survival_2.37-7 lattice_0.20-24
[15] cluster_1.14.4
loaded via a namespace (and not attached):
[1] brew_1.0-6 codetools_0.2-8 colorspace_1.2-4 dichromat_2.0-0 digest_0.6.4 evaluate_0.5.1
[7] gtable_0.1.2 httr_0.2 labeling_0.2 MASS_7.3-29 memoise_0.1 munsell_0.4.2
[13] parallel_3.0.3 proto_0.3-10 RColorBrewer_1.0-5 RCurl_1.95-4.1 scales_0.2.3 stringr_0.6.2
[19] tools_3.0.3 whisker_0.3-2
tempdir() is R's session-wide temporary working directory, so by unlinking it you've removed the location that R uses for all kinds of temporary files. You want tempfile(). The return value is a temporary path at which you could write a file or create a directory, or...
mydir <- tempfile()
basename(mydir) %in% dir(tempdir()) # FALSE
if (!dir.create(mydir))
stop("failed to create my temporary directory")
basename(mydir) %in% dir(tempdir()) # TRUE
## ...
unlink(mydir, recursive=TRUE)
basename(mydir) %in% dir(tempdir()) # FALSE

What can I do about frequent, unreproducible segfault errors in R 3.0.1?

After upgrading to R 3.0.X, I've started getting pretty frequent, unreproducible segfault errors like those found by this asker. I never had one of these errors before with R 2.X.X. For example, this is the session info for a long block of code that just caused a fault. However, after R crashed, I ran the entire block of code again and there was no error.
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
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] klaR_0.6-8 ggplot2_0.9.3.1 labdsv_1.5-0 MASS_7.3-26 mgcv_1.7-22
[6] cluster_1.14.4 sparcl_1.0.3 FD_1.0-11 vegan_2.0-7 permute_0.7-0
[11] geometry_0.3-3 magic_1.5-4 abind_1.4-0 ape_3.0-8 ade4_1.5-2
[16] plyr_1.8
loaded via a namespace (and not attached):
[1] class_7.3-7 colorspace_1.2-2 dichromat_2.0-0 digest_0.6.3
[5] e1071_1.6-1 grid_3.0.1 gtable_0.1.2 labeling_0.1
[9] lattice_0.20-15 Matrix_1.0-12 munsell_0.4 nlme_3.1-109
[13] proto_0.3-10 RColorBrewer_1.0-5 reshape2_1.2.2 scales_0.2.3
[17] stringr_0.6.2
Sometimes R freezes completely and I have to do a force quit, but other times, it allows me to exit with options for a core dump or saving the workspace.
Someone in another post suggested setting options(CBoundsCheck=T) and that seemed to work for a while but I am still getting frequent faults.
I don't think these faults are related to any specific kind of calculation or function as I got one the other day after starting a new session and only setting my working directory and options. The code that triggered the fault and the system info would look like this:
#Set my working directory
setwd("~/Documents/School Spring 2013/Quaternary Dissasembly/Functional Diversity Basefile 3")
#Keep getting segfaults all the time. This might fix it
options(CBoundsCheck=T)
sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
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 help anyone could give me to find and fix the bug or the incorrect settings I have would be greatly appreciated. Thank you.
-M

Resources