-
Notifications
You must be signed in to change notification settings - Fork 4
Follow-up on feedback from CAA #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
6a0a55c
5ffe7b1
a91aa86
d628e49
5517f9f
2a7edf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #' @name bdl_strategies | ||
| #' | ||
| #' @title Strategies to replace "below detection limit" values | ||
| #' | ||
| #' @description ... | ||
| #' | ||
| #' @param x a vector, derived from a data.frame column | ||
| #' @param colname name of the respective data.frame column | ||
| #' @param marker values indicating "below detection limit" | ||
| #' @param value value to replace values identified as "below detection limit" | ||
| #' @param ... further arguments passed to or from other methods | ||
| #' | ||
| #' @rdname bdl_strategies | ||
| #' | ||
| #' @examples | ||
| #' plot(1,1) | ||
| #' | ||
| NULL | ||
|
|
||
| #' @rdname bdl_strategies | ||
| #' @export | ||
| bdl_strategy_default <- function(x, colname, marker = c("b.d.", "bd", "b.d.l.", "bdl", "<LOD", "<"), ...) { | ||
| bdl_indices <- which(grepl(paste(marker, collapse = "|"), x, perl = FALSE)) | ||
| x[bdl_indices] <- NA_character_ | ||
| return(x) | ||
| } | ||
|
|
||
| #' @rdname bdl_strategies | ||
| #' @export | ||
| bdl_strategy_none <- function(x, colname, ...) { | ||
| return(x) | ||
| } | ||
|
|
||
| #' @rdname bdl_strategies | ||
| #' @export | ||
| bdl_strategy_negative <- function(x, colname, value = "99999", ...) { | ||
| bdl_indices <- which(grepl("^-\\d*\\.?\\d*\\*?\\d*\\^?\\-?\\d*$", x)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realized that the bdl strategy functions are called by Sorry for missing this initially. I was too focused on the
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will revert the code to your generalised version then. Thanks! |
||
| x[bdl_indices] <- value | ||
| return(x) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These bdl strategy functions can not have additional arguments just so. They are not called by the user (
bdl_strategy_default()), but forwarded by the user as a higher order function toas_ASTR(bdl_strategy_default). That means they can only have the arguments expected byas_ASTRwhen it calls it throughbuild_constructors():Think of it in terms of types:
as_ASTRtakes a bdl_strategy argument, which is a function of typeIf you now give it a function of type
as you do with
function(x, colname, marker = c("b.d.", "bd", "b.d.l.", "bdl", "<LOD", "<"), ...)then this is just inconsitent. If R had a static type system this would not compile.Probably this still works here in the extremely flexible R, because
markerhas a default value here. But users can not changemarkeras things stand, and then it's misleading to expose the argument.If you want the user to be able to change
markerthen you have three options:bdl_markertoread_ASTRandas_ASTRand forward it to thebdl_strategythroughbuild_constructors. This is pretty tedious if you want to cover the arguments of multiple different strategy functions.It takes
markerand returns a function that has the markers encoded in its body. This is then exactly whatas_ASTRexpects and can handle.