Comments (3)
I've started on an implementation and have a better working example in README here:
https://github.com/MilesMcBain/noprobs
from attempt.
Hey Miles,
Thanks, that's indeed a very nifty idea!
For the map / nest thing, I think you can already do this with try_catch_df()
library(titanic)
library(tidyverse)
library(attempt)
#>
#> Attaching package: 'attempt'
#> The following object is masked from 'package:dplyr':
#>
#> if_else
fitting_fn <- function(a_df){
glm(Survived ~ ., family = binomial, data = a_df)
}
titanic_train %>%
group_by(Pclass) %>%
nest() %>%
mutate(result = map(data, ~try_catch_df(fitting_fn(.x)))) %>%
unnest(result)
#> # A tibble: 3 x 6
#> Pclass data call error warning value
#> <int> <list> <chr> <lgl> <chr> <list>
#> 1 3 <tibble [491 … fitting_fn… NA glm.fit: algorithm did n… <S3: g…
#> 2 1 <tibble [216 … fitting_fn… NA glm.fit: algorithm did n… <S3: g…
#> 3 2 <tibble [184 … fitting_fn… NA glm.fit: algorithm did n… <S3: g…
Created on 2019-06-07 by the reprex package (v0.2.1)
What you've got though (and which indeed misses in {attempt}
is something that returns the message, so far only errors and warnings are returned.
Also, you return a list of warning and a list of error, which seems to be a better implementation as it allows to return mutliple warnings
For the map_try_catch_ltbl
, I think we can get what you want by just removing thedo.call(rbind())
from map_try_catch_df()
. The implementation you've made with the withCallingHandlers
is indeed a better way to go, so that we can get the message out of it.
> attempt::map_try_catch_df
function (l, fun)
{
do.call(rbind, lapply(l, function(x) eval(try_catch_df_builder(x,
fun))))
}
library(attempt)
map_try_catch_ltbl <- function (l, fun) {
lapply(l, function(x) eval(attempt:::try_catch_df_builder(x, fun)))
}
map_try_catch_ltbl(list(1, "a", 2), log)
#> [[1]]
#> call error warning value
#> 1 .Primitive("log")(1) NA NA 0
#>
#> [[2]]
#> call error
#> 1 .Primitive("log")("a") non-numeric argument to mathematical function
#> warning value
#> 1 NA error
#>
#> [[3]]
#> call error warning value
#> 1 .Primitive("log")(2) NA NA 0.6931472
Created on 2019-06-07 by the reprex package (v0.2.1)
Also, I love your any_problems idea!
Would you be willing to PR this into {attempt}
(and of course list you as ctb
) ?
from attempt.
Yes I'd be willing to PR! :) Do you like that example name? I don't really it was just the first thing I could think of.
from attempt.
Related Issues (9)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from attempt.