I'm running into an issue where plyr consistently crashes when an error is thrown from the supplied function
> require(plyr)
Loading required package: plyr
Warning message:
package ‘plyr’ was built under R version 3.0.2
> df <- data.frame(group=c("A","A","B","B"), num=c(11,22,33,44))
> ddply(df, .(group), function(x) {x})
group num
1 A 11
2 A 22
3 B 33
4 B 44
> ddply(df, .(group), function(x) {stop("badness")})
called from: (function ()
{
.rs.breakOnError(TRUE)
})()
Error in .fun(piece, ...) : badness
Browse[1]>
# Crashes immediately
Is anyone aware of why this may be occuring and how to prevent it (other than avoiding errors of course)?
(I'm running R 3.0.1 on platform: i386-w64-mingw32/i386 (32-bit) through RStudio 0.98.274 under Windows 7)
EDIT
As a workaround, I am redirecting any errors as warnings which avoids the crashes
ddply(df, .(group), function(x) tryCatch(stop("badness"), error = function(e) warning(e)) )
Will report what happens here if I manage to align the plyr and R versions.
I got the same issue on R 3.1.1 and plyr 1.8.1.
To fix it, I just reinstalled the package from source.
install.packages("plyr", type = "source")
Related
I have a function in my package that uses tryCatch for condition handling.
f <- function(){
tryCatch(expr = warning("?!"), error = function(c) {message(c); 3},
warning = function(c) {message(c); 4})
}
When I try to write a unit test for this with testthat, I always get an error related to restart or muffleWarning. Any idea how to solve this? I want to match output to 4 during warning, in this case.
test_that("test_f", {
suppressWarnings(output <- f())
expect_equal(output, 4)
})
> devtools::test()
error: test_f
no 'restart' 'muffleWarning' found
Backtrace:
1. base::suppressWarnings(output <- f()) tests/testthat/test_file.R:27:2
14. base::invokeRestart("muffleWarning")
version R version 3.6.3 (2020-02-29)
os Ubuntu 16.04.6 LTS
system x86_64, linux-gnu
testthat * 2.3.2
The environment:
Platform: x86_64-redhat-linux-gnu (64-bit)
R version 3.3.0 (2016-05-03)
[1] RMySQL_0.10.9 DBI_0.4-1
Basically what I'm doing is getting whit a query a data.frame and then adding a column with sapply() running a function, but most of the time(some times work) I get this error:
Error in .local(dbObj, ...) : INTEGER() can only be applied to a 'integer', not a 'raw' Calls: getData ... dbClearResult -> dbIsValid -> dbIsValid -> .local -> .Call In addition: There were 50 or more warnings (use warnings() to see the first 50) Execution halted
This is my code:
myFunc <- function(row){
res <- dbGetQuery(conn,my_sub_query)
return(res[1,1])
}
df <- dbGetQuery(conn,my_query)
df$newCol <- sapply( df$col1, myFunc)
Fails most of the time, please help and thanks in advance
I was working with baby names data set and encountered below error while using transform function. Any guidance/suggestion would be highly appreciated. I did reinstalled the packages but of no avail.
Mac OS X (Mountain Lion)
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
library(stringr)
require(stringr)
bnames1 <- transform(bnames1,
first = tolower(str_sub(name,1,1)),
last = tolower(str_sub(name,-1,1)),
vowels = vowels(name),
length= nchar(name),
per1000 = 10000 * prop,
one_par = 1/prop
)
Error in tolower(str_sub(name, 1, 1)) :
lazy-load database '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/stringr/R/stringr.rdb' is corrupt
In addition: Warning messages:
1: In tolower(str_sub(name, 1, 1)) :
restarting interrupted promise evaluation
2: In tolower(str_sub(name, 1, 1)) : internal error -3 in R_decompress1
internal error -3 is often a functioning of installing on top of a loaded package. Restart R and restart your application. There may be other issues, but until you do this you won't be going much further.
Try
remove.packages("stringr")
install.packages("stringr")
In data.table-1.9.2 the following syntax was allowed:
dt[some_column == max(some_column)]
This allowed for nice, easy and fast filtering on the column itself.
Now on data.table-1.9.4 the following error is thrown running the same code
object 'some_column' not found
I have two questions.
1.) Why change this beautiful attribute?! It'd be nice of Matt Dowle to comment here.
2.) Does anyone have some clever solutions to replace this method? Something other than
new.var <- dt[, max(some_column)]
dt[some_column == new.var]
Regards,
K
The last binary version on CRAN for Mac SL branch is 1.9.2 which is what I had, and as you say that is not a problem:
> d <- data.table(a=1:10)
> d[a==max(a),]
a
1: 10
So I got the most recent CRAN source version 1.9.4 and compiled with these results after unloading pkg:data.table and reloading :
> d <- data.table(a=1:10)
> d[a==max(a),]
Error in `[.data.table`(d, a == max(a), )
object 'CsubsetVector' not found
After restarting:
> d <- data.table(a=1:10)
> d[a==max(a),]
Error in eval(expr, envir, enclos) : object 'a' not found
After building 1.9.5 from source (Mac 3.1.2 SL branch) using the instructions at Github the problem evaporated:
> require(data.table)
Loading required package: data.table
data.table 1.9.5 For help type: ?data.table
*** NB: by=.EACHI is now explicit. See README to restore previous behavior.
> d[a==max(a),]
Error: object 'd' not found
> d <- data.table(a=1:10)
> d[a==max(a),]
a
1: 10
I am trying to run the example for doSMP posted here:
require(plyr) # make sure you have 1.2 or later installed
x <- seq_len(20)
wait <- function(i) Sys.sleep(0.1)
system.time(llply(x, wait))
require(doSMP)
workers <- startWorkers(2) # My computer has 2 cores
registerDoSMP(workers)
system.time(llply(x, wait, .parallel = TRUE))
and I get the following warnings:
Warning messages:
1: <anonymous>: ... may be used in an incorrect context: ‘.fun(piece, ...)’
2: <anonymous>: ... may be used in an incorrect context: ‘.fun(piece, ...)’
What do these warnings mean, and should I worry about them?
edit:
getRversion() = 2.12.2
packageDescription("plyr", fields="Version") = 1.4
packageDescription("doSMP", fields="Version") = 1.0-1
Are you using windows?
I get the same error on linux.
And also the same error with doSNOW.
Then I tried with doMC instead of doSMP and it worked fine.