-
Notifications
You must be signed in to change notification settings - Fork 17
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
Layer templates don't accept added parameters on left side of =
within function
#141
Comments
@haodafa2019 I'm impressed by the nuance of the issues that you've been finding here. Ok - for starters, in your first layer template the layer is formed correctly with the pass through parameters. In the second template ("boa_demo_desc_template"), the template would need to be build like this: new_layer_template(
"boa_demo_desc_template",
group_desc(...) %>%
set_custom_summaries(
blank_=as.numeric(NA),
nmiss=sum(!is.na(.var)),
nmiss_pct=sum(!is.na(.var))/length(.var)*100,
missing = sum(is.na(.var)),
missing_pct= sum(is.na(.var))/length(.var)*100
) %>%
set_format_strings(
{desc_label} = f_str("xx", blank_),
"n (%)" = f_str("xx (xx.x)", nmiss, nmiss_pct),
"Missing (%)" = f_str("xx (xx.x)", missing, missing_pct),
"Mean +/- SD"= f_str("xx.x +/- xx.xx", mean,sd, empty='NA'),
"Median" = f_str("xx.x", median),
"Q1; Q3" = f_str("xx.x; xx.x", q1, q3, empty=c(.overall='NA')),
"Min; Max" = f_str("xx; xx", min, max)
)
) But - I see how you ended up where you did, because R doesn't like this syntax, and you'll get this error:
So, basically layer templates can't do what you're trying to do here (right now), so I'll label this as a bug. That said, I see what you're trying to do here - and honestly clever way to do it! Something we haven't supported very well are tables where you nest your row labels down into one column, and that's basically what you're trying to do with the "Age" label here. "Age" should just be submitted in your by variables like this: use_template("boa_demo_desc_template", AGE2, by = "AGE") But we don't offer an elegant way to do what you're trying to do. #129 shows the feature request issue of how I'd like to support this. Basically, I'd like to introduce a function that creates the blank row labelling "Age" like you want to do here, and that way you'd avoid trying to add the template parameter and custom function for Thanks for the continued interaction and it's cool to see people trying to use some of the more advanced features of Tplyr! |
=
within function
This registers as a syntax error, so new_layer_template("test",
group_desc(...) %>%
set_format_strings(
`{my_param}` = f_str("xx", n)
)
)
> get_layer_templates()
$test
Template name: test
Template parameters: None
Template code:
{
group_desc(...) %>% set_format_strings(`{my_param}` = f_str("xx", n))
} |
@mstackhouse , thank you so much for the quick response.
|
Prerequisites
layer template question
Description
I have one question on new_layer_template or question on add_total_row in desc_count.
I tried to develop template for categorical variable summary and continues variable summary to generate the demo tables.
In template boa_demo_count_template, I added paramter {count_label} so I can specify the label. And it works!
I tried to add similar parameter in template boa_demo_desc_template ( "desc_label" = f_str("xx", blank_), ) so I can add label for the vairable. but {des_label} not works. The purpose of this step is too add label above the summary as there is no total_row option in desc_count function. So either in template there is way to add self-defined label in template or add label for continued variable are fine. can you give suggestion?
Below are the code I tried,
# demo_count
# demo description
# derive AGE2 for testing missing (%) in demo table
# run table by using template
And below is are the result:
as you see the first row desc_label is one parameter I expect, by adding paramter like add_params = list(desc_label="Age") so I can obtain the table with summary label for continued variables
# A tibble: 11 × 5
Versions
1.1.0
You can get this information from executing
sessionInfo()
.R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
The text was updated successfully, but these errors were encountered: