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
Related
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
I have been getting this error for the first time for commands that used to run well before:
# conversion from char to numeric:
as.numeric(df$col) -> df$col
Error: (converted from warning) NAs introduced by coercion
# running metafor
rma(yi, vi, data=r1s2)
Error: (converted from warning) Studies with NAs omitted from model fitting.
The issue must be with the R environment as these commands are running perfectly on a different computer. The only wrong I can think of is installing a package from GitHub or updating R a few hours ago. The only relevant answer I've found so far is also not working:
Sys.setenv(R_REMOTES_NO_ERRORS_FROM_WARNINGS="true")
This seems to be a warning level issue. If the warning level is 2, warnings become errors. From the documentation, my emphasis.
warn:
integer value to set the handling of warning messages. If warn is negative all warnings are ignored. If warn is zero (the default) warnings are stored until the top–level function returns. If 10 or fewer warnings were signalled they will be printed otherwise a message saying how many were signalled. An object called last.warning is created and can be printed through the function warnings. If warn is one, warnings are printed as they occur. If warn is two (or larger, coercible to integer), all warnings are turned into errors.
old_ops <- options(warn = 2)
warning("this is a warning")
#> Error in eval(expr, envir, enclos): (converted from warning) this is a warning
x <- "a"
as.numeric(x)
#> Error in eval(expr, envir, enclos): (converted from warning) NAs introduced by coercion
options(old_ops)
Created on 2022-06-25 by the reprex package (v2.0.1)
If you say that
The issue must be with the R environment as these commands are running perfectly on a different computer.
then check if you have a file named .RData in your R startup directory. If you have one, then you probably set the warning level in a previous session and now it is being restored every time you run R. Delete this file and this behavior will go away.
See also this SO post.
I have two functions, f_ that throws an error and f that throws a warning before calling f_.
f_ <- function() stop()
f <- function() {
warning()
f_()
}
Since I have a warning before the error, R produces "additionnal warning messages", but the message in this warning is not my f warning but the error produced in f_ called a 2nd time :
> f()
Error in f_() :
In addition: Warning message:
In f() :
Error in f_() :
It seems to works as expected if the error is produced in the same function or by a built_in function.
f <- function() {
warning()
stop()
}
> f()
Error in f() :
In addition: Warning message:
In f() :
Can someone helps me to understand what is happening there ?
Thanks for any help.
I'm running R version 3.3.2 on x86_64-w64-mingw32 using RStudio.
I think this is caused by the Rstudio error inspector. When encountering an error Rstudio displays the possibility for traceback and debugging. I believe that is the source of the confusion (my own included). The "second" error is simply a feature in Rstudio which assists in debugging as seen below. Note the two buttons on the right allowing you to "show traceback" and "rerun with debug".
In Rstudio
As you can see below, if you run R in a terminal,
this "additional" error is not there.
In a terminal
In your global options in Rstudio, under General tab, you can turn off the use of the debug error handler. You can also do this under Debug -> On Error.
Rstudio will then not display the "additional" message.
Edit:
Upon investigating a bit further, there is something odd going on though. Below, I tried to make the error and warning message a bit more informative with the following observations:
Calling f() many times in a row, it is not entirely clear to me when the error inspector appears and when it does not.
When the error inspector does appear, the warning message is not displayed. When the error inspector does not appear, the warning message is displayed.
I do not know anything about Rstudio's internals, but it is quite definitely the error inspector causing these minor issues.
I am currently running an example in the glmnet documentation (https://cran.r-project.org/web/packages/glmnet/glmnet.pdf page 3):
> x=matrix(rnorm(100*20),100,20)
> y=rnorm(100)
> fit1=glmnet(x,y)
> plot(fit1,xvar="lambda")
However, I get this error message
Error in as.vector((beta %*% ones) > 0) :
no method for coercing this S4 class to a vector
and I need help to understand why the error occurs.
I run exactly the code you put and it works.
Maybe you should remove your workspace and run again the code.
In R I get the following errors any time I hit View() or data.frame and I do not understand why. It happened suddenly.
> View(Fhat_all)
Error in .External2(C_dataviewer, x, title) : unable to start data viewer
In addition: Warning message:
In View(Fhat_all) : unable to open display
> da <- data.frame(comb[true_comb_RMSE[1],1], comb[true_comb_RMSE[1],2],
comb[true_comb_KS[1],1],comb[true_comb_KS[1],2])
Error in (function (env, objName) :
could not find function "object.size"
I checked this other page in Stackoverflow Can't use either View() or edit() functions, getting "Error in .External2(C_dataviewer, x, title) : invalid device" error message but I didn't understand how to fix it. So I hit locale on terminal and got this result:
Last login: Mon Mar 21 16:47:07 on ttys000
MacBook-Pro:~ "username"$ locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=
MacBook-Pro:~ "username"$ LC_CTYPE = C R
-bash: LC_CTYPE: command not found
so I hit LC_CTYPE=C R on the the terminal as by suggestion and tried to view a vector in R, but I got the same error message:
> View(w)
Error in .External2(C_dataviewer, x, title) : unable to start data viewer
In addition: Warning message:
In View(w) : unable to open display
Can you please help me? Thank you.
I had the same issue. I opened XQuartz and then the View() function worked.
Experienced this after updating some packages.
Restart R worked for me (in RStudio: Ctrl+Shift+F10). After that, the error vanished and View worked well again.
I had the same error when using the jagsUI package, which masks the View function. Perhaps you have conflicts between packages?
Check potential conflicts between functions by calling conflicts(detail=TRUE) (Taken from this answer for finding which functions are masked in R).
Easiest workaround in my case was calling detach("package:jagsUI", unload = TRUE) once I finished using JAGS.
Delete the view(), then it will work!