Cannot find 'convert' using SaveGIF function in animation package - r

I'm having trouble with the SaveGIF function in library (animation). The function gives me this error:
Error in cmd.fun(sprintf("%s --version", convert), intern = TRUE, ignore.stdout = !interactive(), :
unused argument(s) (ignore.stdout = !interactive())
I cannot find ImageMagick with convert = 'convert'
NULL
Warning message:
In im.convert(img.files, output = movie.name, convert = convert, :
Please install ImageMagick first or put its bin path into the system PATH variable
What confuses me is that I do have convert on my system, so I'd expect SaveGIF to be able to find it without any trouble:
me#my-laptop:~$ convert --version
Version: ImageMagick 6.5.7-8 2010-12-02 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009
How do I add convert's bin path to the system PATH variable?
Edit: I'm using Ubuntu, not Windows.

You probably did not edit your PATH variable. On Windows 7 (but will probably work on earlier versions to) go to:
start menu
Right click computer -> properties
Advanced System Settings
Environment Variables
Then under "System variables" (the lower pane) find the variable "path", select it
and click edit.
You are interested in the content of Variable value (maybe copy it to a text editor to read it better). It should contain the link to imagemagick in it, seperated by semicolons from other variables. For me the path to imagemagick is:
C:\Program Files\ImageMagick-6.6.7-Q16
Make sure you only add it, not change anything else to the path variable. Add it with a semicolon.

Usually we do not need to manually set the PATH variable under Linux. I'm using Ubuntu as well, but I cannot reproduce your error. What's your R version?
> sessionInfo()
R version 2.13.0 (2011-04-13)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] animation_2.0-4
As far as I can see, the error comes from the function system() instead of not being able to find convert. The argument ignore.stdout came in R 2.12.1, so you must be using a lower version of R. The current version is 2.13.0, and I recommend you to upgrade to the latest version. See http://cran.r-project.org/bin/linux/ubuntu/ for how to keep R updated with CRAN.

You can find where your convert function lives with system("which convert", intern=TRUE) and then you (may be able to) add that to your PATH variable with
Sys.setenv(PATH=...)

After attempting all of these fixes as well as these and these to no success, I used alternative software to make the conversion from the png files that were successfully created with saveHTML. Several programs are described here. I am a Windows user and found the simple instructions contained in that site for VirtualDub quickly accomplished this task.

Related

R error when installing packages (summarytools)

edit: all screenshots are displayed
I'm teaching stats in Rstudio and we're using the summarytools package. A few of my students are getting different error messages, with the same overall result that the package is not properly installed.
Alex's error seems to download, but not sure if it is installing and the library function cannot find the summarytools package.
Aroun's error is happening mid-install, something about failing to install or load a supporting package 'stringr'.
Zoey's error says something about a non-zero exit status.
While I can run stats in R, I'm a complete newb at troubleshooting package errors. Since I'm not directly experiencing these errors, it is double-difficult to troubleshoot. Any help is appreciated.
Best,
Shawn
It is difficult to judge from these errors, what actually happens. Still, my conjecture is broken or incomplete R installations.
When using R on Windows, please double-check that you installed
1) a single version of R
2) Rtools giving compilers to R
Without Rtools, R will only function in a very limited sense as it cannot compile packages and depends on binary packages that might have been compiled with different versions of R on different platforms.
If these two ideas don't solve the problem and as you are teaching, please think about using a single VM or Docker image (my approach in teaching) such that you and all your students have exactly the same software platform. With this approach, you can use a stable Linux, where R is integrated and well-tested.
Overview
I think - because without each of your student's sessionInfo() output I am only able to make recommendations based off their error messages - the following will help:
Alex: install.packages( pkgs = c("digest", "rapportools") ).
Zoey & Aroun: install.packages( pkgs = "stringr" ).
Afterwards, have all three run install.packages( pkgs = "summarytools" ).
If all else fails, you can have all three run the following commands to install the package from GitHub: install.packages("devtools") followed by devtools::install_github("dcomtois/summarytools").
Methodology
I installed summarytools with the following command install.packages( pkgs = "summarytools" ). All of your students did the same, which led me to print out my session information using sessionInfo():
R version 3.4.3 (2017-11-30)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux
Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] summarytools_0.8.2
loaded via a namespace (and not attached):
[1] Rcpp_0.12.16 matrixStats_0.53.1 codetools_0.2-15 digest_0.6.14 bitops_1.0-6
[6] plyr_1.8.4 magrittr_1.5 stringi_1.1.7 pryr_0.1.4 rapportools_1.0
[11] tools_3.4.3 stringr_1.3.0 pander_0.6.1 RCurl_1.95-4.10 rsconnect_0.8.8
[16] compiler_3.4.3 htmltools_0.3.6
Based on the error messages from each of your students, the installation of summarytools seems to be failing due to dependency packages (i.e. rapportools, digest, and stringr) not downloading with their download of summarytools.
This is an updated answer
For Alex's problem, I suspect the apostrophe in the path ("Alex's PC") might be the culprit.
For Zoey's and Aroun's, it's not clear, maybe some permission issues...?
Possible solutions (for all three cases)
1 - Preferably, try installing through Github:
install.packages('devtools') # if not already installed
library(devtools)
install_github("dcomtois/summarytools")
2 - If solution 1 fails or is not possible for whatever reason, install the latest binaries instead of the most recent (source) version.
install.packages('summarytools', type = 'binary')
3- If all that fails, I'd suggest trying this prior to installation as a last resort. Normally this shouldn't be necessary, but it can't hurt. After completion, try regular install or one of the two previous solutions.
install.packages(c('htmltools', 'matrixStats', 'pander', 'pryr',
'rapportools', 'RCurl', 'Hmisc', 'rstudioapi',
'rmarkdown', 'stringr'))
install.packages('knitr', dependencies = TRUE)
update.packages(ask = FALSE, repos = 'https://cran.rstudio.org')

'translateCharUTF8' must be called on a CHARSXP Execution halted

I installed Microsoft-R-Open 3.4.0 on a Red Hat Linux Enterprise 7.3 machine following the instructions https://mran.microsoft.com/documents/rro/installation/ .
R starts up and seems to be doing fine at first sight. However, when I try to list the files in a directory with the command
files <- list.files(path="/home/username/directory_name/", pattern="*.Rda",, full.names=T, recursive=FALSE)
I get the error
translateCharUTF8' must be called on a CHARSXP
Execution halted
On my local windows machine the command works fine.
Googling this nothing really comes up except that the installation might be broken.
The strange thing is, that if I copy and paste the command into R and execute it, it does not work, but if I copy and paste it into R and change that command in a way that should not change its result but only add spaces or something like that it might run. E.g. changing it to
files <- list.files(path = "/home/username/directory_name/", pattern = "*.Rda",, full.names = T, recursive = FALSE)
might work, might not work and return the same error, or might execute but when I then type "files" that might return
[1]Error: 'getCharCE' must be called on a CHARSXP
When using R from the R-foundation (https://www.r-project.org/, installed via EPEL), I get the same error and behaviour.
The command sessionInfo() returns the following:
sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server 7.3 (Maipo)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
uname -mrs gives me:
Linux 3.10.0-514.el7.x86_64 x86_64
Any help would be greatly appreciated,
best regards
Stefan
Your files have names containing accented characters. Changing them to pure-ASCII names should fix the problem.
For Example
unicode_and_raw_filename = paste0("/tmp/\u1234", as.raw("A"))
training_rows <<- read.csv(unicode_and_raw_filename, header = FALSE)
produces:
'translateCharUTF8' must be called on a CHARSXP, but got 'raw'
Looks like R internals has some spaghetti code in charset conversion for Latin2, ISO_8859-2, UTF-8, and CP1252: https://stat.ethz.ch/R-manual/R-devel/library/base/html/iconv.html

R Error in validObject(.Object) when running as script, but not in console

The following code works fine in the R console (R 3.3.0):
m = system.file("external/pores_1.mtx", package = "Matrix")
x = Matrix::readMM(m)
I can put it in a script and it runs fine in R console as:
source("test.R")
However, when I execute it as Rscript --vanilla test.R or Rscript test.R, I get an error:
Error in validObject(.Object) :
invalid class “dgTMatrix” object: Not a valid 'Mnumeric' class object
Calls: <Anonymous> -> new -> initialize -> initialize -> validObject
Execution halted
I don't know if this is related to that specific function. I am guessing this has something to do with how Rscript works, but I used it with various other libraries and functions previously and have never seen anything like this. Any idea what is happening?
I can confirm ... I'm getting the exact same error when running a script containing a call to glmnet(). I was able to trace it back to the Matrix package, on which glmnet depends.
I back-rev'd my R version from v3.3.3 -> v3.3.2 and the error disappeared. I then checked the sessionInfo() between the two and discovered that the version of the Matrix package differed ... it is 1.2-8 (in v3.3.3) and 1.2-7.1 (in v3.3.2). To confirm, I simply replaced the "OK" version of Matrix (7.1) with the "broken" version and the error returned.
I can also confirm that explicitly loading the methods package via library(methods) resolves the error (somehow?), which explains the differing behavior between the console call and the Rscript call from the command line.
So, it appears we have 2 work-arounds:
library(methods)
back rev your version of Matrix to 1.2-7.1.
Neither is super satisfactory ... I'd just like to know what's going on with Matrix 1.2-8. Maybe it'll be bug-fixed in the next version.
If you're interested, here is my sessionInfo():
R version 3.3.3 (2017-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets base
other attached packages:
[1] glmnet_2.0-5 foreach_1.4.3 Matrix_1.2-8
loaded via a namespace (and not attached):
[1] codetools_0.2-15 grid_3.3.3 iterators_1.0.8 methods_3.3.3
[5] lattice_0.20-35
Oh dear.
I'm pretty (not 100% !) sure that this problem should not apply in newer version of R and Matrix.
Still I would claim this is not a Matrix bug in a proper sense, rather either an 'Rscript' vs 'R' bug -- as #Stu Field mentions already; Rscript does not by default attach the methods package to the search() path, but regular R does.
OTOH, R CMD check Matrix nowadays should try to run Matrix without the methods package being in the search path, and hence the problem should not be present from Matrix 1.2-9 and newer, i.e., by default from R 3.4.0 and newer or then update the 'Matrix' package if you have an older version of R.
Again: Can you please confirm that the problem is gone with R 3.4.0 (which has Matrix 1.2-9 "along with it") ?
Here is a more useful example script, I called Rscript-tst.R.
Run as
Rscript --vanilla Rscript-tst.R > Rscript-tst.Rout 2>&1
or (as myself with many R versions installed) something like
`R-3.4.0 RHOME`/bin/Rscript --vanilla Rscript-tst.R > Rscript-tst.Rout_R340 2>&1
Rscript-tst.R :
options(echo = TRUE)# << even with "Rscript" or --slave ...
(m <- system.file("external/pores_1.mtx", package = "Matrix"))
packageDescription("Matrix")
## This *load*s the Matrix package but does not attach it to search()
str(Matrix::readMM)
sessionInfo()
x <- Matrix::readMM(m)
## used to fail because 'methods' was not "there" (in Rscript only)

Troubleshooting R script called from Rscript.exe

I have an R script that runs fine in RStudio. I am trying to schedule it to run regularly in Windows Task Scheduler with RScript.exe. It failed.
Then I tried running it from command line and noticed an error below.
D:\development\projects\SSCDAPOC\trunk\src\scripts>"C:\Program Files\R\R-3.2.2\bin\x64\Rscript.exe" batch_read_rss_selected.R
Loading required package: xml2
Error in as.vector(x, "list") :
cannot coerce type 'environment' to vector of type 'list'
Calls: do.call ... <Anonymous> -> lapply -> as.list -> as.list.default
Execution halted
When I sourced directly in RStudio for the same script, it worked perfectly fine.
Any tips on how I can investigate and troubleshoot this?
R session info below in case of use:
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_Singapore.1252 LC_CTYPE=English_Singapore.1252
[3] LC_MONETARY=English_Singapore.1252 LC_NUMERIC=C
[5] LC_TIME=English_Singapore.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rvest_0.3.1 xml2_0.1.2
loaded via a namespace (and not attached):
[1] httr_1.0.0 selectr_0.2-3 R6_2.1.1 magrittr_1.5 tools_3.2.2 curl_0.9.4
[7] Rcpp_0.12.2 stringi_1.0-1 stringr_1.0.0 XML_3.98-1.3
After some further searching I found two ways to make this work:
Instead of using Rscript.exe, I force the input into R.exe. i.e. instead of
Rscript.exe batch_read_rss_selected.R earlier, I usedR.exe -f batch_read_rss_selected.R. This worked, and dumped every single line of code in the script on screen also.
Change the script to explicitly include library(methods) . It seems this is not needed for the script to function when running from within R (RStudio IDE in my case), but is needed for Rscript.exe for my script. Now it executes similarly both on command line and from R environment.
I used cmd to call Rscript.exe in Task Scheduler, then gave it an absolute path to my R script, which further defined the output to an rmarkdown file. I should note that I also had to install pandoc on my computer to get it to work (https://pandoc.org/installing.html). But I now have a rmarkdown report which runs every day, and draws data directly from an MSAccess database to provide me with a summary I can send my boss and staff.
Code:
program/script = cmd
additional argument =
/c C:/<yourpath>/Rscript.exe "C:/<yourpath>/run_report.R"
in run_report.R I specify the output:
rmarkdown::render("C:/<yourpath>/filename.Rmd", output_format= NULL,output_file="C:/yourpath>/filename.pdf", knit_root_dir=NULL, runtime="auto", clean=TRUE, run_pandoc = TRUE, quiet=TRUE)

Where are the fix() and edit() functions in RStudio Server?

I followed the official guide to install RStudio Server. Everything works fine, but the functions, fix and edit, are not available.
For instance, I have a data.frame called "data" as follows.
1,2,3
4,5,6
7,8,9
The command "View(data)" works fine. But when I execute the command "edit(data)" or "fix(data)", it comes some error messages.
The error messages of "fix(data)" :
Error in .External2(C_dataentry, datalist, modes) :
unable to start data editor
In addition: Warning message:
In edit.data.frame(get(subx, envir = parent), title = subx, ...) :
unable to open display
The error message of "edit(data)" :
Error in edit : Editing of data frames and matrixes is not supported in RStudio.
I ran the same codes on my local rstudio (windows 8.1), and all the functions work fine!
It's really wired... Anyone can help me? Thanks a lot!
p.s. I read this post already, but it doesn't work for me.
sessionInfo:
R version 3.1.3 (2015-03-09)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
locale:
[1] LC_CTYPE=zh_TW.UTF-8 LC_NUMERIC=C LC_TIME=zh_TW.UTF-8
[4] LC_COLLATE=zh_TW.UTF-8 LC_MONETARY=zh_TW.UTF-8 LC_MESSAGES=zh_TW.UTF-8
[7] LC_PAPER=zh_TW.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=zh_TW.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.1.3
I had the same problem, but then I installed the XQuartz package from here: https://www.xquartz.org/
And then another thread, from a while back, reminded me that I needed to restart my Mac for the x11 app to take effect: https://stackoverflow.com/a/36486555

Resources