I'm going through the vignette example in the openxlsx package in R Statistics, but I can't save the workbook and I can't figure out why. The code below is a modified example from the vignette, just to keep it simple.
setwd("c:/users/kenneth/documents/r/2014-04-29_openxlsx")
require(openxlsx)
require(ggplot2)
wb <- createWorkbook()
addWorksheet(wb, sheetName = "Motor Trend Car Road Tests", gridLines = FALSE)
addWorksheet(wb, sheetName = "Iris")
addWorksheet(wb, sheetName = "Conditional Formatting")
saveWorkbook(wb=wb, file="basics.xlsx", overwrite=TRUE) ## save to working directory
The error message I get is:
Warning message:
running command '"zip" -r1 "c:/users/kenneth/documents/r/2014-04-29_openxlsx/basics.xlsx" "[Content_Types].xml" "_rels" "docProps" "docProps/app.xml" "docProps/core.xml" "xl" "xl/_rels" "xl/_rels/workbook.xml.rels" "xl/charts" "xl/drawings" "xl/drawings/_rels" "xl/printerSettings" "xl/printerSettings/printerSettings1.bin" "xl/printerSettings/printerSettings2.bin" "xl/printerSettings/printerSettings3.bin" "xl/styles.xml" "xl/tables" "xl/tables/_rels" "xl/theme" "xl/theme/theme1.xml" "xl/workbook.xml" "xl/worksheets" "xl/worksheets/_rels" "xl/worksheets/_rels/sheet1.xml.rels" "xl/worksheets/_rels/sheet2.xml.rels" "xl/worksheets/_rels/sheet3.xml.rels" "xl/worksheets/sheet1.xml" "xl/worksheets/sheet2.xml" "xl/worksheets/sheet3.xml" ' had status 127
This is my sessioninfo:
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252
[3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C
[5] LC_TIME=Danish_Denmark.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_0.9.3.1 openxlsx_1.0.3
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 digest_0.6.4 grid_3.1.0 gtable_0.1.2
[5] MASS_7.3-31 munsell_0.4.2 plyr_1.8.1 proto_0.3-10
[9] Rcpp_0.11.1 reshape2_1.4 scales_0.2.4 stringr_0.6.2
[13] tools_3.1.0
I have updated to the most recent version of R, devtools and Rtools.
I think the issue here is that R can not find the zip application that comes with Rtools.
You can check if the Rtools bin directory is in the system PATH from R with the command
shell("PATH")
The output should look something like this (depending on where you installed Rtools):
PATH=c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin;C:\Windows\system32;C:\... etc
If the Rtools\bin directory doesn't appear anywhere in the string add it in.
Instructions to edit system path can be found here:
http://www.java.com/en/download/help/path.xml")
If this doesn't work email me and I'll help you out further (email is in the vignette)
Related
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.
I am running testthat in Rstudio (Windows 0.98.1056), and I get the following error. It seems to have appeared after I updated Rstudio and the installed R packages, but I suspect the two may not be directly related. The error occurs also on a very simple test file. Has anyone encountered this?
file: tests/test-all.R
library(testthat)
library(matrixUtils)
test_package("matrixUtils")
file: tests/testthat/matrixUtils-test.R
context("testa")
test_that("subsetting by one dimension", {
a <-1
expect_equal(a, 1)
})
Error message:
==> Sourcing R files in 'tests' directory
Error: '\.' is an unrecognized escape in character string starting "'\." Execution halted
Exited with status 1.
sessionInfo() R version 3.1.1 (2014-07-10) Platform: x86_64-w64-mingw32/x64 (64-bit)
locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages: [1] grid stats graphics grDevices utils datasets methods base
other attached packages: [1] magrittr_1.1.0 matrixUtils_0.2 testthat_0.8.1 dplyr_0.2.0.99 reshape2_1.4 ggplot2_1.0.0 gridExtra_0.9.1 [8] zoo_1.7-11
loaded via a namespace (and not attached): [1] assertthat_0.1 colorspace_1.2-4 digest_0.6.4 gtable_0.1.2 lattice_0.20-29 MASS_7.3-34 munsell_0.4.2 [8] parallel_3.1.1 plyr_1.8.1 proto_0.3-10 Rcpp_0.11.2 scales_0.2.4 stringr_0.6.2 tools_3.1.1
>
It's hard to check your error without the package. Some ideas:
This was a similar error reported in #187 on github/hadley/testthat.
Update testthat package. Latest is 0.9.1.
Issue was closed but looks hard to reproduce. #hadley suggests a fix
check that devtools is enabled under project options in RStudio
renkun-ken added library(devtools) as a last resort in his Rprofile.
I start RStudio without .Rprofile which runs library(devtools). Test from Test package does not work, then I run devtools::test() as you suggest, and it works.
If this does not work. Check your paths and use file.path() to create paths using strings in your package. This error seems to crop up with paths misspecified.
Hope this helps gappy and you get the "woot" happy test messages soon!
M
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
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.
After successfully creating a graph with this code:
qplot(ethcat3, Percent, data=g_02_1b_pov, geom="bar", stat="identity")
I would like to save the graph as a png, pdf, or jpeg file. I used the following code:
ggsave(file="test.png")
Instead of outputting the graph, I receive the following (error) message:
Saving 7.82 x 3.75 in image
Error in eval(expr, envir, enclos) : attempt to apply non-function
and no file is saved. (Instead of png, I also tried the extensions pdf, and jpeg).
I found in a forum that I should use the command: dev_mode() and has_devel()
the output of dev_mode is:
> dev_mode()
Dev mode: OFF
and
> has_devel()
/Library/Frameworks/R.framework/Resources/bin/R --vanilla CMD SHLIB foo.c
sh: make: command not found
Error: Command failed (1)
However, I don't know what to do with this feedback?
Can anyone help me with this problem? I think I used the same approach in the past on a PC and it worked without a problem. I'm wondering if it is connected to my installation on a mac?
Thanks a lot!
Addition: #DWin asked for the sessionInfo() output:
d> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] C/en_US.UTF-8/C/C/C/C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] devtools_0.8 reshape2_1.2.1 plyr_1.7.1 ggplot2_0.9.2.1
loaded via a namespace (and not attached):
[1] MASS_7.3-18 RColorBrewer_1.0-5 RCurl_1.95-3 colorspace_1.2-0
[5] dichromat_1.2-4 digest_0.5.2 evaluate_0.4.2 grid_2.15.1
[9] gtable_0.1.1 httr_0.2 labeling_0.1 memoise_0.1
[13] munsell_0.4 parallel_2.15.1 proto_0.3-9.2 scales_0.2.2
[17] stringr_0.6.1 tools_2.15.1 whisker_0.1