install.packages() ignoring option to convert warning to error? - r

I'm trying to find a simple way to make install.packages() throw an error if it fails (rather than just a warning).
What I've tried
Setting options(warn=2) converts warnings into errors. Example:
options(warn=2)
warning()
# Error: (converted from warning)
I expected this would now error:
install.packages('thispackagedoesntexist')
# Warning in install.packages :
# package ‘thispackagedoesntexist’ is not available for this version of R
#
# A version of this package for your version of R might be available elsewhere,
# see the ideas at
# https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
yet it still just gives a warning (no error).
Question
How can install.packages() be made to error (rather than simply warn) on any sort of failure?
Note:
There are a few nice ways of making install.packages() error instead of warning, but I'm scouting for something much more lightweight, preferably without installing other packages, which options() would achieve nicely (if I can get it working).

This is an RStudio "feature".
First I wondered why the warning isn't printed in red. Then I looked at install.packages (in RStudio) and saw this:
> install.packages
function (...)
.rs.callAs(name, hook, original, ...)
<environment: 0x1408432c8>
> getAnywhere(.rs.callAs)
A single object matching ‘.rs.callAs’ was found
It was found in the following places
tools:rstudio
with value
function (name, f, ...)
{
withCallingHandlers(tryCatch(f(...), error = function(e) {
cat("Error in ", name, " : ", e$message, "\n", sep = "")
}), warning = function(w) {
if (getOption("warn") >= 0)
cat("Warning in ", name, " :\n ", w$message, "\n",
sep = "")
invokeRestart("muffleWarning")
})
}
<environment: 0x1181b4928>
See how warnings are handled and how the printed "warning" isn't actually a warning but cat output?
If I run your code in Rgui, I see this:
> options(warn=2)
> install.packages('thispackagedoesntexist')
Error: (converted from warning) package ‘thispackagedoesntexist’ is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
So, I suggest you go to the RStudio developers and complain that they use cat to misleadingly print "errors" and "warnings".
You can avoid RStudio's masking of install.packages the usual way:
> options(warn=2)
> utils::install.packages('thispackagedoesntexist')
Error: (converted from warning) package ‘thispackagedoesntexist’ is not available for this version of R
A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

Related

Error trying to download Github package on r

I am trying to download the package 'seegSDM' package but keep getting an error despite trying a couple different ways.
I am using Rx64 3.6.2 and have been using the package 'githubinstall' to try and download the package.
library(githubinstall)
gh_install_packages("seegSDM")
When I use this I get the error
"Error: unexpected string constant in:
"suppressPackageStartupMessages(.getRequiredPackages(quietly = TRUE))
tools:::makeLazyLoading("seegSDM", "C:/Users/Laptop'"
Execution halted
ERROR: lazy loading failed for package 'seegSDM'
* removing 'C:/Users/Laptop/Documents/R/win-library/3.6/seegSDM'
Error: Failed to install 'seegSDM' from GitHub:
(converted from warning) installation of package ‘C:/Users/Laptop'~1/AppData/Local/Temp/Rtmpe6YLGi/file26b07cc06130/seegSDM_0.1-9.tar.gz’ had non-zero exit status
In addition: Warning message:
In fread(download_url, sep = "\t", header = FALSE, stringsAsFactors = FALSE, :
Found and resolved improper quoting out-of-sample. First healed line 4848: <<Puriney honfleuR "Evening, honfleuR" by Seurat>>. If the fields are not quoted (e.g. field separator does not appear within any field), try quote="" to avoid this warning.
Any advice? I need to use the function neasrestLand so I can nudge points on a raster to the nearest land.
It think you need to add the organization name (SEEG-Oxford). The package installs fine with
remotes::install_github("SEEG-Oxford/seegSDM"
and I suppose it might also work with
gh_install_packages("SEEG-Oxford/seegSDM")

Error building R package vignette. Error in if (idx > 0) sprintf("default-%s.tex) else "default.tex" : missing value where TRUE/FALSE needed

I am building an R package.
==> devtools::document(roclets = c('rd', 'collate', 'namespace', 'vignette'))
Updating package documentation
Writing NAMESPACE
Loading package
.
.
.
Writing NAMESPACE
Updating vignettes
Rebuilding projectR.Rmd
I get the following error after this
Error in if (idx > 0) sprintf("default-%s.tex", template_versions[idx]) else "default.tex" :
missing value where TRUE/FALSE needed
Calls: suppressPackageStartupMessages ... create_output_format -> do.call -> <Anonymous> -> create_latex_template
Execution halted
Exited with status 1.
I am not sure what is causing the error. I thought because it calls roxygen2::roxygenize, it may be originating from there but the package doesn't contain this error message. Can someone please guide me in resolving this?
You are getting this error from a bug in older versions of BiocStyle. As part of the vignette processing in the version you have, the following line is run:
idx <- match(TRUE, version >= template_versions)
However, if version >= template_versions returns NA, then idx will also be NA. Then the if (idx > 0) check throws the error you got.
You can see the commit where they fixed this bug here, by changing the above line to
idx <- match(TRUE, version >= template_versions, nomatch = 0)
So, you need version 2.13.1 or later to avoid this bug. One way to do that could be to install from GitHub:
library(devtools)
install_github("Bioconductor/BiocStyle")

Attempting to use source() in r, but gives grep error

I am attempting to use Muxviz, and I believe that I installed all of the required dependencies (octave, R, g++, gfortan, and GDAL), but I'm getting an error when I try to use "source('muxVizGUI.R')". I says
Error in if (grep("3.2", version$version.string) != 1) { :
argument is of length zero
Any suggestions? I just made sure that R is > 3.2.x.

How to update and recompile nlme source code in R

I am attempting to update the ‘nlme’ package so that I can use great circular distances for the correlation in the gls command. I'm attempting to edit the source code with the changes specified here.
I am unsure about how to proceed in re-compiling the package with the updated source code. I am able to edit the source within the .tar.gz, but when I try to install the package from my local folder, I receive:
Installing package into ‘C:/Users/HSRG1/Documents/R/win-library/3.0’
(as ‘lib’ is unspecified)
* installing *source* package 'nlme' ...
files 'R/corStruct.R', 'R/gls.R', 'R/lme.R' have the wrong MD5 checksums
** libs
*** arch - i386
ERROR: compilation failed for package 'nlme'
* removing 'C:/Users/HSRG1/Documents/R/win-library/3.0/nlme'
Warning messages:
1: running command '"C:/PROGRA~1/R/R-30~1.0/bin/x64/R" CMD INSTALL -l "C:\Users\HSRG1\Documents\R\win-library\3.0" "nlme_3.1-111.tar.gz"' had status 1
2: In install.packages("nlme_3.1-111.tar.gz", repos = NULL, type = "source") :
installation of package ‘nlme_3.1-111.tar.gz’ had non-zero exit status
The functions R/corStruct.R', 'R/gls.R', 'R/lme.R are those which I am trying to edit. I do not know what this error means, particularly the bit about having incorrect checksums (I suspect the other errors follow). I found the following link: http://r.789695.n4.nabble.com/R-3-0-0-wrong-MD5-checksums-for-Windows-td4663348.html which discusses a different linebreak command which is implemented when compiling from Windows, but I do not know how this is relevant (or soluble) as the source has no linebreak declarations.. There is clearly something I'm missing.
I am using a Windows 64 bit computer - please let me know if there is any other information I need to provide.
UPDATE: As suggested I have tried to implement the corRGaus correlation in the ramps package. When I try to use the corRGaus correlation I get the following error:
y = runif(50, 1, 40)
x = runif(50, 1,20)
LC= c(rep(1,25), rep(2,25))
lat = runif(50,-90,90)
long = runif(50,180,180)
fit <- lme(y ~ x,random = ~x|LC, cor = corRGaus(form = ~lat+long))
Error in `coef<-.corSpatial`(`*tmp*`, value = value[parMap[, i]]) :
NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning messages:
1: In nlminb(c(coef(lmeSt)), function(lmePars) -logLik(lmeSt, lmePars), :
NA/NaN function evaluation
2: In nlminb(c(coef(lmeSt)), function(lmePars) -logLik(lmeSt, lmePars), :
NA/NaN function evaluation
3: In nlminb(c(coef(lmeSt)), function(lmePars) -logLik(lmeSt, lmePars), :
NA/NaN function evaluation
4: In nlminb(c(coef(lmeSt)), function(lmePars) -logLik(lmeSt, lmePars), :
I am not sure what this error means, nor how to remedy it.
As a side note, after installing ramps, I am no longer able to use the corGaus correlation until restarting R (even if I detach the ramps package).

Error in running the gWidgets2Qt demo

I've got this error while running the demo of the gWidgets2Qt package:
> demo(gWidgets2Qt)
demo(gWidgets2Qt)
---- ~~~~~~~~~~~
Type <Return> to start :
> ## run examples
> require(gWidgets2)
> options(guiToolkit="Qt")
> ## run examples
> source(system.file("examples", "run_examples.R", package="gWidgets2"))
Error in envRefSetField(x, what, refObjectClass(x), selfEnv, value) :
‘.visible’ is not a field in class “GWindow”
please check also this question I've just asked for session info and a similar error I've got with the cranvas package which I think might be related to the above. Thanks a lot.
EDIT:
following the tips from #jverzani I tried a simple code which worked. Then I did some tests:
I get this when detaching the package
detach("package:gWidgets2Qt", unload=TRUE)
There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: In FUN(X[[2L]], ...) :
Created a package name, ‘2013-05-23 07:40:37’, when none found
Tried to re-load and run the demo but still didn't work
I restarted ubuntu and tried again
library(gWidgets2Qt)
demo(gWidgets2Qt)
it run correctly, I only get error with the ex-graphics.R example
which fails to run with this error at the first attempt:
Error in qsceneDevice(width, height, pointsize, family, the_scene) :
unused argument (the_scene)
In addition: Warning message:
In .removePreviousCoerce(class1, class2, where, prevIs) :
methods currently exist for coercing from “AlternativeSingleEnum” to “character”; they will be replaced.
Error in qinvoke(<environment>, "initScene", ...) :
Implementation failed for method 'R::gWidgets2Qt::QtDevice::initScene'
and this one at the next attmpts:
Error in qsceneDevice(width, height, pointsize, family, the_scene) :
unused argument (the_scene)
Error in qinvoke(<environment>, "initScene", ...) :
Implementation failed for method 'R::gWidgets2Qt::QtDevice::initScene'
But all the other examples work. However, as soon as I load cranvas, with
> library(cranvas)
Attaching package: ‘cranvas’
The following object is masked from ‘package:gWidgets2’:
visible, visible<-
demo(gWidgets2Qt) fails again and detaching cranvas
> detach("package:cranvas", unload=TRUE)
There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: In FUN(X[[2L]], ...) :
Created a package name, ‘2013-05-23 08:37:43’, when none found
demo(gWidgets2Qt) runs again. Has been this incompatibility already seen? Is this depending on invisible being masked from gWidgets2?
I'm not sure why this isn't working. I just installed the whole thing (qtbase, qtutils, gWidgets2, gWidget2Qt) on a linux setup and the demo starts. The ones involving graphs don't really work, but the basic demo does. To see if everything is working, try with something simple:
w <- gwindow("something simple")
b <- gbutton("click me", container=w)
addHandlerChanged(b, handler=function(h,...) {
gmessage("Hello world", parent=w)
})
If that doesn't work then there are installation issues

Resources