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
Related
I have been running a bash script (under Ubuntu) that calls and runs some R scripts to plot some maps with ggplot2. As it is a production system I don't update any new R or package releases. But recently I tried to install plotly with an error message output.
Now, when trying to run the script (calling a php webpage trhough a browser; that was running fine for a lot of time) an error with crayon package halts and exits the script without plotting the maps.
'/usr/lib/R/bin/R --slave --no-restore --no-save --no-restore --file=./RAMS-mapa-onades-zones-manual.R'
Loading required package: sp
Loading required package: methods
Checking rgeos availability: TRUE
Error : .onLoad failed in loadNamespace() for 'pillar', details:
call: loadNamespace(name)
error: there is no package called 'crayon'
Error: package or namespace load failed for 'ggplot2'
Execution halted
But if I run from a terminal or with RStudio server crayon package is loaded, ggplot2 is also properly loaded, and the maps are produced.
crayon package (located at /home/meteo/R/i686-pc-linux-gnu-library/3.1) called as
library("crayon", lib.loc= c("/home/meteo/R/i686-pc-linux-gnu-library/3.1", "/usr/local/lib/R/site-library", "/usr/lib/R/library"))
R session info on Rstudio Server:
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: i686-pc-linux-gnu (32-bit)
Running under: Ubuntu precise (12.04.5 LTS)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C
[7] LC_PAPER=C LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C LC_IDENTIFICATION=C
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] crayon_1.3.4 rgdal_0.9-1 rgeos_0.3-8 raster_2.3-24 gpclib_1.5-5 mapproj_1.2-2 maps_2.3-9
[8] stringr_0.6.2 plyr_1.8.1 ggplot2_3.2.0 maptools_0.8-34 sp_1.2-3
loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 magrittr_1.5 tidyselect_0.2.5 munsell_0.5.0 colorspace_1.2-4 lattice_0.20-33 R6_2.4.0
[8] rlang_0.3.4 dplyr_0.8.1 tools_3.2.2 gtable_0.1.2 withr_2.1.2 digest_0.6.8 lazyeval_0.2.2
[15] assertthat_0.2.1 tibble_2.1.3 purrr_0.3.2 glue_1.3.1 labeling_0.3 pillar_1.4.1 scales_1.0.0
[22] foreign_0.8-66 pkgconfig_2.0.2
Maybe there is a version conflict? How do I check?
what version of R is in /usr/lib/R/bin/R? Basically it appears you are in a slight "dependency hell" I would run /usr/lib/R/bin/R and check to see if crayon is installed there. #Alexis is correct though, it is not wise to mix versions like that. Let R handle library location unless you are trying to separate packages. Check the libraries for 3.2.2 and see if crayon is installed. you may have switched your R version since plotly depends on R >=3.2.0 https://cran.r-project.org/web/packages/plotly/
I think the easy fix would be to correct your .libpaths() i.e not call the 3.1 library and install the correct version of the packages you need.
OR
switch from R 3.2 back to R 3.1
I am unable to render Rmarkdown documents with Rscript if they have dplyr SQLite calls in them. Take this MWE (test.Rmd) which calls for a table in a local copy of the dplyr::lahman_sqlite() table.
---
title: "TestFile"
output: html_document
---
```{r setup, include=FALSE}
library(dplyr)
lahman <- src_sqlite("lahman.sqlite")
```
```{r}
tbl(lahman, "Batting")
```
In a live R console session I can call rmarkdown::render("test.Rmd"), and this document is built as expected. But if I call Rscript -e 'rmarkdown::render("test.Rmd")' on the command line, I get the following error:
Quitting from lines 12-13 (test.Rmd)
Error in UseMethod("db_query_fields") :
no applicable method for 'db_query_fields' applied to an object of class "SQLiteConnection"
Calls: render ... make_tbl -> structure -> op_base_remote -> db_query_fields
I've attached my sessionInfo below, but I've duplicated this error on OS X as well as Ubuntu.
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin15.5.0 (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
other attached packages:
[1] dplyr_0.5.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.5 digest_0.6.9 assertthat_0.1 R6_2.1.2 DBI_0.4-1 formatR_1.4 magrittr_1.5 evaluate_0.9
[9] RSQLite_1.0.0 stringi_1.1.1 rmarkdown_0.9.6 tools_3.3.1 stringr_1.0.0 Lahman_4.0-1 yaml_2.1.13 htmltools_0.3.5
[17] knitr_1.13 tibble_1.0
The problem comes from the fact that when using Rscript the methods package is not loaded. It's therefore required to load it explicitly by adding library(methods) in the setup chunk for instance.
I am running an Rscript using crontab. In that Rscript command, I am trying to load googlesheets package using library(googlesheets). Note, I have already installed googlesheets package is already installed.
I am getting this error:
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/sparavas/R/x86_64-pc-linux-gnu-library/3.2/purrr/libs/purrr.so':
/home/sparavas/R/x86_64-pc-linux-gnu-library/3.2/purrr/libs/purrr.so: ELF file OS ABI invalid
In addition: Warning message:
package 'googlesheets' was built under R version 3.2.3
Error: package or namespace load failed for 'googlesheets'
Execution halted
When I run the same script from terminal, I am not getting this error. This errors comes only when ran through crontab.
I also tried to get below sessionInfo (if this might help to detect the problem) :
R version 3.2.0 (2015-04-16)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] C
attached base packages:
[1] methods stats graphics grDevices utils datasets base
other attached packages:
[1] devtools_1.11.1 reshape2_1.4.1 DIVER_0.1.1 hash_2.2.6
[5] dplyr_0.4.3
loaded via a namespace (and not attached):
[1] Rcpp_0.12.1 digest_0.6.8 withr_1.0.1 assertthat_0.1 R6_2.1.0
[6] plyr_1.8.2 DBI_0.3.1 magrittr_1.5 stringi_0.4-1 tools_3.2.0
[11] stringr_1.0.0 parallel_3.2.0 memoise_1.0.0
I also tried reinstalling packages purrr, dplyr, googlesheets. Please suggest what I am missing.
Also what does:
ELF file OS ABI invalid
mean?
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.
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.