How to solve- Error: (converted from warning) - r

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.

Related

There is no nn$result.matrix in neuralnet in r

I did neuralnet in R
test_wocoal=sample(dim(df_wocoal)[1],8570)
sx=scale(df_wocoal);sx=as.data.frame(sx)
train=sx[-test_wocoal,];test=sx[test_wocoal]
n=names(train)
form=as.formula(paste('Primary_Air_Flow~',paste(n[!n %in% 'primary_Air_Flow'],collapse='+')))
nn=neuralnet(form,data=train,hidden=3,linear.output,err.fct="ce",stepmax=1e+08,threshold=0.01)
the ftn 'neuralnet' was ended sucessfully.
So, i was doing 'compute'
But, the R gave me a warnings.
pre=compute(nn,test[,-1])
Error in nrow[w]*ncol[w] :non-numeric argument to binary operator
In addition: Warning message:
In un.na(weights): in.na() applied to non-(list or vector) of type 'NULL'
So, i checked my data frame, but there is no NA(all cases are complete) and all columns are numeric.
I don't know why that error is comming
and, i checked component(?) in 'nn'
there is no 'result.matrix'.
'nn' has only 'numHiddenNodes','data','hidden','linear.output','err.fct','stepmax','threshold'
What problem is in here? How to solve it?

Seems like R can't see properly the variables in my function (pb pointsToMatrix)

I have created a function which run well on my local environment, but fail on the server.
function(dataset1,nom_col_lon1,nom_col_lat1,dataset2,nom_col_lon2,nom_col_lat2,nom_col_ID2){
require(geosphere)
mat.dist<- distm(dataset1[,c(nom_col_lon1,nom_col_lat1)], dataset2[,c(nom_col_lon2,nom_col_lat2)], fun=distHaversine)
lon=match(nom_col_lon2,colnames(dataset2))
dataset1$compLon=dataset2[,lon][apply(mat.dist,1,which.min)]
rm(lon)
lat=match(nom_col_lat2,colnames(dataset2))
dataset1$compLat=dataset2[,lat][apply(mat.dist,1,which.min)]
rm(lat)
ID=match(nom_col_ID2,colnames(dataset2))
dataset1$compID=dataset2[,ID][apply(mat.dist,1,which.min)]
dataset1$dist_min=apply(mat.dist,1,min)
rm(mat.dist)
return(dataset1)}
It works well on my local session, but when I call it on the server, I got this error:
ARCEP_SFR_2G=min_dist(ARCEP_SFR_2G,"lon","lat",ANFR_SFR_2G,"lon","lat","ID")
Error in .pointsToMatrix(p1) * toRad :
non-numeric argument to binary operator
In addition: Warning messages:
1: In .pointsToMatrix(x) : NAs introduced by coercion
2: In .pointsToMatrix(y) : NAs introduced by coercion
In the two dataset that I use, nom_col_lon and nom_col_lat are numeric. There is no NA. When I check the environment for min_dist, it's "global environment". Any idea of what could be the problem?
EDIT:
When I run
mat.dist<- distm(ARCEP_SFR_2G[,c("lon","lat")], ANFR_SFR_2G[,c("lon","lat")], fun=distHaversine)
it works well. The problem happens only when I call the function.
EDIT2:
Exemple of dataset:
Technologie=c("2G","3G")
Operateur=c("Ope1","Ope2")
lat=c(46.2,46.1)
lon=c(5.34,5.51)
ID=c("ID1","ID2")
x=as.data.table(cbind(Technologie,Operateur,lat,lon,ID))
x$lat=as.numeric(x$lat)
x$lon=as.numeric(x$lon)
The server is a Linux server. My local session is under windows.

Error using DEXSeqDataSetFromHTSeq

Currently I am trying to understand DEXSeq package. I have a design tsv file and 7 files which contains Counts. Now would like to run the following command
library("DEXSeq");
design=read.table("dexseq_design.tsv", header=TRUE, row.names=1);
ecs = DEXSeqDataSetFromHTSeq(countfiles=c("M0.txt", "M1.txt", "M2.txt", "M3.txt", "M4.txt", "M5.txt", "M6.txt", "M7.txt"), design=design, flattenedfile="genome.chr.gff");
The last command gives and error
Error in class(sampleData) %in% c("data.frame") :
error in evaluating the argument 'x' in selecting a method for function '%in%':
Error: argument "sampleData" is missing, with no default
What does this error means and how to fix it? While loading the package DEXSeq there was a warning
Warning message:
replacing previous import by ‘ggplot2::Position’ when loading ‘DESeq2’

testthat: handling both warning and value

What's the best way to handle calls that generate a warning but then also return a value?
e.g.
> require(testthat)
> expect_warning(log(-1))
> expect_equal(log(-1), NaN)
Warning message:
In log(-1) : NaNs produced
I want to write the test such that the call to log(-1) should both (a) generate a warning and (b) return the value NaN. The way above works, but seeing the "Warning message:" at the bottom might confuse people. Should I suppress warnings temporarily?
require(testthat)
expect_warning(val <- log(-1))
expect_true(is.nan(val))

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