similar to: recovering from errors with lapply()

Displaying 20 results from an estimated 20000 matches similar to: "recovering from errors with lapply()"

2012 May 25
1
question about TryCatch and lapply
Folks: I've replaced an outer for-loop with lapply and it works great. But, I can't seem to do the following type of exception handling: tryCatch(dlmMLE(x)$value==Inf,error = function(e) NULL) which basically says if the likelihood is Inf, throw an error. But what I want it to do is just go to the next index in the list. When I was using a for-loop I used:
2017 Aug 14
2
recursive lapply and keeping track of data
Hello, I'm writing a program that takes a tree in input (nested lists) and returns a copy of it replacing the leaves with something else (eg: a computation done on the original leaves). In the example below, the tree is composed by countries and cities, and the leaves (children of the cities) are vectors of numbers. The program takes this tree and replaces the vectors at the bottom by their
2017 Aug 14
0
recursive lapply and keeping track of data
You could replace your 'depth' argument with one that shows where in the original data you are at: leaf.func <- function(data, where) { if(is.null(data)) stop("Null data at ", deparse(where)) return(mean(data)) } visit.level <- function(data, where = integer()) { if (length(where) == 2) { return(leaf.func(data, where)) } else
2008 Sep 04
2
using complete.cases() with nested factors
Hello, This maybe a newbie question. I have a dataframe that looks like the sample at the bottom of the email. I have monthly precipitation data from several sites over several years. For each site, I need to extract years that have a complete series of 12 monthly precipitation values, while excluding that year for sites with incomplete data. I can't figure out how to do this gracefully
2010 Feb 17
1
skip lapply item for conditions(RAM, execution time)
Hi, I use lapply with a function from a package, and every 20th to 50th function execution (out of 500 to 10 000 times) fails for some unknown reason. RAM consumption ever increases (out of limit) and execution time is endless. I am not going to debug the package. (I rather feel like an end-user.) If it was Java, I'd wrap the function in a try...catch statement like about try{
2010 Nov 16
2
Debugging segfault in foreach
Hi, I'm using R-2.12 on a linux 64bit machine. When I run a chunk of code inside a foreach() %do% { ...} or %dopar% {...} (with doMC backend) I keep getting a segfault. Running the *same* code within lapply(something, function(x) ... ) doesn't result in any segfaults. I'll paste the output below, but I'm not sure it would be helpful. I'm more curious how to go about smoking
2019 May 22
1
make running on.exit expr uninterruptible
Hi, Is there currently any way to guarantee that on.exit does not fail to execute the recorded expression because of a user interrupt arriving during function exit? Consider: f <- function() { suspendInterrupts({ on.exit(suspendInterrupts(cntr_on.exit <<- cntr_on.exit + 1L)) cntr_f <<- cntr_f + 1L }) TRUE } It is possible to interrupt this function such that cntr_f
2018 Sep 19
5
segfault issue with parallel::mclapply and download.file() on Mac OS X
I have an lapply function call that I want to parallelize. Below is a very simplified version of the code: url_base <- "https://cloud.r-project.org/src/contrib/" files <- c("A3_1.0.0.tar.gz", "ABC.RAP_0.9.0.tar.gz") res <- parallel::mclapply(files, function(s) download.file(paste0(url_base, s), s)) Instead of download a couple of files in parallel, I get a
2008 Aug 14
3
tryCatch question
I would like to use the 'tryCatch' function but am having a hard time getting my head around it. In 'C' like languages try/catch/finally means try a block of statements and if any throw an error then do the statements in the catch block and then error or not always do the staements in the finally block. In 'R' as best as I can tell the block of staements in the try block is
2012 Feb 23
1
segfault when using data.table package in conjunction with foreach
Hi all, I'm trying to use the package read.table within a foreach loop. I'm grabbing 500M rows of data at a time from two different files and then doing an aggregate/tapply like function in read.table after that. I had planned on doing a foreach loop 39 times at once for the 39 files I have, but obviously that won't work until I figure out why the segfault is occurring. The
2016 Apr 12
3
formula argument evaluation
I have a simple function such as: foo <- function(x) { call <- lapply(match.call(), deparse) testit <- capture.output(tryCatch(eval(x), error = function(e) e)) if (grepl("Error", testit)) { return(call$x) } } and I would like to detect a formula when x is not an object: # this works > foo(A + B) [1] "A + B" # but this doesn't >
2019 Apr 05
2
Deep Replicable Bug With AMD Threadripper MultiCore
The following program is whittled down from a much larger program that always works on Intel, and always works on AMD's threadripper with lapply but not mclappy. With mclapply on AMD, all processes go into "suspend" mode and the program then hangs. This bug is replicable on an AMD Ryzen Threadripper 2950X 16-Core Processor (128GB RAM), running latest ubuntu 18.04. The R version
2011 Jul 10
1
Help with tryCatch
Having a hard time understanding the help files for tryCatch. Looking for a little help with the following statement which sits inside a for loop zest[i] <- tryCatch(sapply(getNodeSet(zdoc, "//zestimate/amount"), xmlValue), error=function() zest[i] <-"NA") zest is a numeric vector If the sapply statement evaluates to an error, I'd like to set the value of zest[i]
2020 Sep 24
1
How to use `[` without evaluating the arguments.
Hello R-devel, I am currently attempting to implement an API similar to data.table wherein single bracket subsetting can accept an unquoted expression to be evaluated in the context of my object. A simple example from the data.table package looks like this: DT <- data.table(col1 = c('a', 'b', 'c'), col2 = c('x', 'y', 'z')) DT[col1 ==
2011 Sep 15
1
Where to put tryCatch or similar in a very big for loop
Dear all, I am running a simulation study to test variable imputation methods for Cox models using R 2.9.0 and Windows XP. The code I have written (which is rather long) works (if I set nsim = 9) with the following starting values. >bootrs(nsim=9,lendevdat=1500,lenvaldat=855,ac1=-0.19122,bc1=-0.18355,cc1=-0.51982,cc2=-0.49628,eprop1=0.98,eprop2=0.28,lda=0.003) I need to run the code 1400
2005 Dec 22
1
Problems with passing ... to a function
Dear useRs! I have written a function that should pass argument "m" to the next function, however it does not! Please have a look at the function below that shows a problem and tell me what I am missing. As you can see, the "blocks" argument is passed corectly, while "m" is not. Best, Ales Ziberna opt.par.new<-function( #function for optimizig
2011 Nov 09
3
Help with tryCatch with a for loop
Hello all, I'm a beginner in R working on a script that will produce a set of models (linear, polynomial and logistic) for each location in a dataset. However, the self-starting logistic model often fails - if this happens I would like to just skip to the next iteration of the loop using tryCatch. I've looked at a few examples and read the help file, but didn't understand tryCatch
2010 Oct 06
3
Assigning value to a vector from within a function
Hi all, I am having trouble assigning a value within a vector using a variable defined within a function. I suspect this has something to do with namespaces but I cannot figure it out. Please reply directly to me if you can help. ###begin code #simple vector test<-c(4,5,6) #simple function to get a value from a vector #works just like I would expect, has no problem indexing using the local
2017 Dec 01
3
tryCatch in on.exit()
The following example involves a function whose on.exit() expression both generates an error and catches the error. The body of the function also generates an error. When calling the function wrapped in a tryCatch, should that tryCatch's error function be given the error from the body of the function, since the one from the on.exit has already been dealt with? Currently the outer tryCatch
2023 Jul 26
1
Downloading a directory of text files into R
?s 23:06 de 25/07/2023, Bob Green escreveu: > Hello, > > I am seeking advice as to how I can download the 833 files from this > site:"http://home.brisnet.org.au/~bgreen/Data/" > > I want to be able to download them to perform a textual analysis. > > If the 833 files, which are in a Directory with two subfolders were on > my computer I could read them