I'm trying to use secr.fit() in secr package.
> C<- read.capthist('captfile4.txt', 'trapfile2.txt',detector = 'proximity')
No errors found :-)
> secr0 <- secr.fit(C, model = g0~1, buffer = 100, trace = FALSE)"
"Error in uniroot(naiveRPSVcall, lower = obsRPSV/10, upper = obsRPSV * : f() values at end points not of opposite sign
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
Error in naivecap2(0.001, sigma = tempsigma, cap = cpa) : NA/NaN/Inf in foreign function call (arg 3)" .
Can anyone please tell me why I get this error? Thank You.
Related
I am trying to plot simple weather data in R. I don't know how do I convert the following datetime. Please help.
> datetime
[1] "2022-01-18" "2022-01-19" "2022-01-20" "2022-01-21" "2022-01-22"
[6] "2022-01-23" "2022-01-24" "2022-01-25" "2022-01-26" "2022-01-27"
[11] "2022-01-28" "2022-01-29" "2022-01-30" "2022-01-31" "2022-02-01"
> plot(datetime, temp)
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf
t.test(antibioticdata$Bacteria,
antibioticdata$Inhibition,
alternative = c("two.sided"),
paired = FALSE,
var.equal = FALSE)
Here is my R code to make a t-test for a set of data on antibiotic resistance of bacteria. This gives me the error code:
Error in if (stderr < 10 * .Machine$double.eps * max(abs(mx), abs(my))) stop("data are essentially constant") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In mean.default(x) : argument is not numeric or logical: returning NA
2: In var(x) :
Calling var(x) on a factor x is deprecated and will become an error.
Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.
not sure what I am doing wrong
I just met the same error. It's probably due to all the values in each group are the same.
So just write two more "if else". For me, I did
library("greenbrown")
apply(data.table, 1, function(x){
if(AllEqual(x[1:9])){return(1)}
else if(AllEqual(x[1:4]) & AllEqual(x[5:9])){return(0)} else {
t.test(as.numeric(x[1:4]), as.numeric(x[5:9]))->t.results
return(t.results$p.value)
}
})->P.for.data.table
I have a ChartSeries error in my production code. Code Below
chartSeries(Stock, theme = chartTheme("white"), TA=c(addTA(ATR(Stock[,c("High","Low","Close")], n=14)), addTA(ADX(Stock[,c("High","Low","Close")])), addTA(OBV(Stock[,"Close"], Stock[,"Total.Trade.Quantity"])), addTA(chaikinAD(Stock[,c("High","Low","Close")], Stock[,"Total.Trade.Quantity"])), addTA(CMF(Stock[,c("High","Low","Close")], Stock[,"Total.Trade.Quantity"])), addRSI(), addSMI(), addMACD(type = "DEMA"), addBBands(), addDEMA(n = 20, on = 1, with.col = Cl, overlay = TRUE, col = "blue")), subset='last 4 months')
Error Code:
Error in seq.default(min(tav * 0.975, na.rm = TRUE), max(tav * 1.05, na.rm = TRUE), :
'from' must be a finite number
In addition: Warning messages:
1: In min(tav * 0.975, na.rm = TRUE) :
no non-missing arguments to min; returning Inf
2: In max(tav * 1.05, na.rm = TRUE) :
no non-missing arguments to max; returning -Inf
Data file info:
So my data file, an xts styled OHLCV (csv), has 1 row of a total of 4718 rows with 3 NA values (on the first row of the file). The rest of the rows are completely filled with no other NA values.
Edit:
Just omitted the row containing NA values, and still get the same error. So the error has to do something with something else.
Edit 2:
So I found that the error is localized to the addTA(OBV(Stock[,"Close"], Stock[,"Total.Trade.Quantity"])) function/arguments. Any suggestions or tips?
This code resolves your problem:
Stock <- AAPL["2018-08"]
chartSeries(Stock, theme="white")
addTA(OBV(Cl(Stock), Vo(Stock)))
Stock prices chart with OBV added
Warning messages are a good information i want to know. But i just want to know it one time!
So this function throws 2 different warnings and repeats it 20 times.
How can i tell R to only print unique warnings. Im looking for a gerenal solution.
Warning messages:
1: NAs introduced by coercion
2: In sqrt(-1) : NaNs produced
Here is my example:
foobar <- function(n=20) {
for (i in 1:n) {
as.numeric("b")
sqrt(-1)
}
}
foobar()
To return only unique warning strings, use
unique(warnings())
Now, a problem you may have is that your function has more than 50 warnings, in which case warnings() will not catch them all. To workaround this, you can increase nwarnings in options to e.g. 10000 as suggested in the help page of warnings.
options(nwarnings = 10000)
Example:
foobar <- function(n=20) {
warning("First warning")
for (i in 1:n) {
as.numeric("b")
sqrt(-1)
}
warning("Last warning")
}
foobar(60)
unique(warnings())
## Warning messages:
## 1: In foobar(60) : First warning
## 2: NAs introduced by coercion
## 3: In sqrt(-1) : NaNs produced
op <- options(nwarnings = 10000)
foobar(60)
unique(warnings())
## Warning messages:
## 1: In foobar(60) : First warning
## 2: NAs introduced by coercion
## 3: In sqrt(-1) : NaNs produced
## 4: In foobar(60) : Last warning
options(op)
I am writing an R package where only a small subset of the functions use functions from data.table. Following Wickham's advice, I added data.table in the Suggests: field of the DESCRIPTION file. I also added if(! requireNamespace("data.table", quietly=TRUE)) at the beginning of each of my functions using a function from data.table. Moeover, each time, I use a data.table-specific function, I precede it with data.table::.
However, I am still encountering problems. As the FAQ of data.table only deals with the Depends: and Imports: fields of the DESCRIPTION file, does it mean that Suggests isn't an option?
Here is a function causing problems:
depths.per.sample <- function(dat, min.reg.len=30, max.reg.len=500,
min.reg.dep=10, max.reg.dep=100,
min.reg.frac=0.25){
if(! requireNamespace("data.table", quietly=TRUE))
stop("Pkg needed for this function to work. Please install it.",
call.=FALSE)
stopifnot(data.table::is.data.table(dat))
for(col in c("ind", "flowcell", "lane", "start", "end", "depth", "fraction"))
stopifnot(col %in% colnames(dat))
## http://stackoverflow.com/a/8096882/597069
depth=fraction=chrom=ind=flowcell=lane=NULL
data.table::setkey(dat, NULL)
data.table::setkeyv(x=dat, cols=c("ind", "flowcell", "lane"))
depths.sample <- dat[end - start >= min.reg.len &
end - start <= max.reg.len,
list(depth.len=data.table::.N,
depth.min=min(data.table::.SD[,depth]),
depth.med=as.double(median(data.table::.SD[,depth])),
depth.mean=mean(data.table::.SD[,depth]),
depth.max=max(data.table::.SD[,depth]),
depth.q65=quantile(data.table::.SD[,depth], 0.65),
depth.q70=quantile(data.table::.SD[,depth], 0.70),
depth.q75=quantile(data.table::.SD[,depth], 0.75),
depth.q80=quantile(data.table::.SD[,depth], 0.80),
reg.ok=nrow(unique(data.table::.SD[depth >= min.reg.dep &
depth <= max.reg.dep &
fraction >= min.reg.frac,
list(chrom,start,end)]))),
by=list(ind,flowcell,lane)]
return(depths.sample)
}
And here are the errors:
Error in x[j] : invalid subscript type 'list'
In addition: Warning messages:
1: In min(data.table::.SD[, depth]) :
no non-missing arguments to min; returning Inf
2: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
3: In mean.default(data.table::.SD[, depth]) :
argument is not numeric or logical: returning NA
4: In max(data.table::.SD[, depth]) :
no non-missing arguments to max; returning -Inf