Skip to content

Commit 6637b5a

Browse files
authored
Merge pull request #310 from FredHutch/use-base-pipe
Switch to using base pipe
2 parents 26d2ab2 + 975be66 commit 6637b5a

File tree

6 files changed

+57
-56
lines changed

6 files changed

+57
-56
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Improvements for package contributors and maintainers
1919
* Run test knits in a `callr` session to isolate Rmd library calls from main R process (#320)
2020
* Drop dependency on `DataPackageR` (#324)
2121
* VISCtemplates now depends on R >= 4.1.0 (#334)
22+
* Use base pipe `|>` in package and templates (#310)
2223

2324
# VISCtemplates 2.0.2
2425

R/report_functions.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ set_kable_warnings <- function(output_type) {
172172
#'
173173
#' pandoc_markup <- set_markup_warnings(output_type = get_output_type())
174174
#'
175-
#' my_results %>%
176-
#' kable() %>%
175+
#' my_results |>
176+
#' kable() |>
177177
#' cell_spec(pvalue, bold = ifelse(pandoc_markup, TRUE, FALSE))
178178
#'
179179
#' }

inst/templates/visc-project-study-schema.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ study_schema <- function(caption = "{{ study_name }} study schema.") {
1515
"Group B", 10, "Dose B", "Dose B"
1616
)
1717

18-
schema_table %>%
18+
schema_table |>
1919
knitr::kable(
2020
format = VISCtemplates::get_output_type(),
2121
caption = caption,
2222
booktabs = TRUE,
2323
linesep = ""
24-
) %>%
24+
) |>
2525
kableExtra::kable_styling(latex_options = c("hold_position"))
2626
}

inst/templates/visc_empty/skeleton/skeleton.Rmd

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,20 @@ tbl_caption <- "Session reproducibility information"
139139
if (output_type == 'latex') {
140140
141141
# format nicely for PDF with kable and kableExtra
142-
my_session_info$platform_table %>%
143-
kable(booktabs = TRUE, linesep = "", caption = tbl_caption) %>%
144-
kable_styling() %>%
145-
column_spec(1, width = "1in") %>%
142+
my_session_info$platform_table |>
143+
kable(booktabs = TRUE, linesep = "", caption = tbl_caption) |>
144+
kable_styling() |>
145+
column_spec(1, width = "1in") |>
146146
column_spec(2, width = "5.5in")
147147
148148
} else {
149149
150150
# format nicely for Word with flextable
151-
my_session_info$platform_table %>%
152-
flextable() %>%
153-
set_caption(tbl_caption) %>%
154-
set_table_properties(layout = "fixed") %>% # to allow overriding automatic column width
155-
flextable::width(1, 1, unit = "in") %>%
151+
my_session_info$platform_table |>
152+
flextable() |>
153+
set_caption(tbl_caption) |>
154+
set_table_properties(layout = "fixed") |> # to allow overriding automatic column width
155+
flextable::width(1, 1, unit = "in") |>
156156
flextable::width(2, 5.5, unit = "in")
157157
158158
}
@@ -167,10 +167,10 @@ tbl_caption <- "Package reproducibility information"
167167
if (output_type == 'latex') {
168168
169169
# format nicely for PDF with kable and kableExtra
170-
my_session_info$packages_table %>%
170+
my_session_info$packages_table |>
171171
kable(
172172
booktabs = TRUE, linesep = "", caption = tbl_caption, longtable = TRUE
173-
) %>%
173+
) |>
174174
kable_styling(
175175
latex_options = 'repeat_header',
176176
repeat_header_method = 'replace'
@@ -179,8 +179,8 @@ if (output_type == 'latex') {
179179
} else {
180180
181181
# format nicely for Word with flextable
182-
my_session_info$packages_table %>%
183-
flextable() %>%
182+
my_session_info$packages_table |>
183+
flextable() |>
184184
set_caption(tbl_caption)
185185
186186
}

inst/templates/visc_report/skeleton/skeleton.Rmd

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ exampleData_ICS <- visc_load_pdata(
158158
# For this template, load VISCfunctions example data
159159
data('exampleData_ICS', package = 'VISCfunctions', envir = environment())
160160
161-
ICS_adata <- exampleData_ICS %>%
161+
ICS_adata <- exampleData_ICS |>
162162
filter(Population == "IFNg" & Group != 3)
163163
```
164164

@@ -239,8 +239,8 @@ Objectives can be found on ATLAS, in the study protocol, or in the SAP.
239239
```{r response-testing, warning=FALSE}
240240
241241
# example of using VISCfunctions::pairwise_test_bin for analysis
242-
response_results <- ICS_adata %>%
243-
group_by(Stim, Visit) %>%
242+
response_results <- ICS_adata |>
243+
group_by(Stim, Visit) |>
244244
group_modify(
245245
~pairwise_test_bin(
246246
x = .$response,
@@ -252,15 +252,15 @@ response_results <- ICS_adata %>%
252252
latex_output = TRUE,
253253
verbose = FALSE
254254
)
255-
) %>%
255+
) |>
256256
ungroup()
257257
```
258258

259259
```{r magnitude-testing, warning=FALSE}
260260
261261
# example of using VISCfunctions::pairwise_test_cont for analysis
262-
magnitude_results <- ICS_adata %>%
263-
group_by(Stim, Visit, Population) %>%
262+
magnitude_results <- ICS_adata |>
263+
group_by(Stim, Visit, Population) |>
264264
group_modify(
265265
~pairwise_test_cont(
266266
x = .$PercentCellNet,
@@ -272,7 +272,7 @@ magnitude_results <- ICS_adata %>%
272272
digits = 3,
273273
verbose = FALSE
274274
)
275-
) %>%
275+
) |>
276276
ungroup()
277277
```
278278

@@ -307,14 +307,14 @@ See Figure `r insert_ref("fig:example-plot")` and Table `r insert_ref("tab:examp
307307

308308
```{r example-plot, fig.scap="Shorter caption for List of Figures.", fig.cap= "Longer caption that shows under the figure. Explain everything needed to understand the figure here."}
309309
310-
plt_data <- ICS_adata %>%
310+
plt_data <- ICS_adata |>
311311
mutate(
312312
Group = factor(Group),
313313
response_and_group = case_when(response == 0 ~ 'Non-Responders',
314314
response == 1 ~ paste("Group", Group, '(Responders)'))
315315
)
316316
317-
plt_data %>%
317+
plt_data |>
318318
ggplot(aes(x = Group,
319319
y = pmax(PercentCellNet, 0.005),
320320
shape = response_and_group,
@@ -324,7 +324,7 @@ plt_data %>%
324324
scale_color_visc() +
325325
scale_shape_visc() +
326326
geom_boxplot(
327-
data = plt_data %>% filter(response == 1),
327+
data = plt_data |> filter(response == 1),
328328
fill = NA, lwd = .5, outlier.colour = NA
329329
) +
330330
scale_y_log10(
@@ -346,8 +346,8 @@ plt_data %>%
346346

347347
```{r example-tab, results="asis", warning=kable_warnings}
348348
349-
magnitude_tab <- magnitude_results %>%
350-
select(-Population, -contains("Perfect")) %>%
349+
magnitude_tab <- magnitude_results |>
350+
select(-Population, -contains("Perfect")) |>
351351
rename("Median (Range)" = Median_Min_Max, 'Mean (SD)' = Mean_SD)
352352
353353
caption_short <- "Short caption to show in List of Tables."
@@ -356,15 +356,15 @@ caption <- "Long caption to show above table. Explain everything needed to under
356356
357357
if (output_type == 'latex') {
358358
359-
magnitude_tab %>%
359+
magnitude_tab |>
360360
mutate(
361361
MagnitudeTest = pretty_pvalues(
362362
MagnitudeTest, output_type = output_type, sig_alpha = .1,
363363
background = "yellow",
364364
bold = if_else(pandoc_markup , TRUE, FALSE),
365365
italic = if_else(pandoc_markup , TRUE, FALSE)
366366
)
367-
) %>%
367+
) |>
368368
kable(
369369
format = output_type,
370370
longtable = FALSE,
@@ -373,30 +373,30 @@ if (output_type == 'latex') {
373373
escape = FALSE,
374374
caption.short = caption_short,
375375
caption = caption
376-
) %>%
376+
) |>
377377
kable_styling(
378378
font_size = 8,
379379
# Note scale_down will overwrite font_size specifications
380380
latex_options = c("hold_position", "scale_down", "repeat_header")
381-
) %>%
381+
) |>
382382
collapse_rows(
383383
columns = 1:2,
384384
row_group_label_position = "identity",
385385
latex_hline = "full"
386-
) %>%
386+
) |>
387387
kableExtra::footnote("SD: standard deviation.", threeparttable = TRUE)
388388
389389
} else {
390390
391391
# flextable version of table for Word doc output
392392
393-
magnitude_tab %>%
394-
mutate(MagnitudeTest = round_away_0(MagnitudeTest, 3)) %>%
395-
flextable() %>%
396-
bg(i = ~ MagnitudeTest < .1, j = "MagnitudeTest", bg = "yellow") %>%
397-
set_caption(caption) %>%
398-
fontsize(size = 7, part = "all") %>%
399-
merge_v(j = 1:2) %>% # equivalent of collapse_rows
393+
magnitude_tab |>
394+
mutate(MagnitudeTest = round_away_0(MagnitudeTest, 3)) |>
395+
flextable() |>
396+
bg(i = ~ MagnitudeTest < .1, j = "MagnitudeTest", bg = "yellow") |>
397+
set_caption(caption) |>
398+
fontsize(size = 7, part = "all") |>
399+
merge_v(j = 1:2) |> # equivalent of collapse_rows
400400
add_footer_lines("SD: standard deviation.")
401401
402402
}
@@ -418,20 +418,20 @@ tbl_caption <- "Session reproducibility information"
418418
if (output_type == 'latex') {
419419
420420
# format nicely for PDF with kable and kableExtra
421-
my_session_info$platform_table %>%
422-
kable(booktabs = TRUE, linesep = "", caption = tbl_caption) %>%
423-
kable_styling() %>%
424-
column_spec(1, width = "1in") %>%
421+
my_session_info$platform_table |>
422+
kable(booktabs = TRUE, linesep = "", caption = tbl_caption) |>
423+
kable_styling() |>
424+
column_spec(1, width = "1in") |>
425425
column_spec(2, width = "5.5in")
426426
427427
} else {
428428
429429
# format nicely for Word with flextable
430-
my_session_info$platform_table %>%
431-
flextable() %>%
432-
set_caption(tbl_caption) %>%
433-
set_table_properties(layout = "fixed") %>% # to allow overriding automatic column width
434-
flextable::width(1, 1, unit = "in") %>%
430+
my_session_info$platform_table |>
431+
flextable() |>
432+
set_caption(tbl_caption) |>
433+
set_table_properties(layout = "fixed") |> # to allow overriding automatic column width
434+
flextable::width(1, 1, unit = "in") |>
435435
flextable::width(2, 5.5, unit = "in")
436436
437437
}
@@ -446,10 +446,10 @@ tbl_caption <- "Package reproducibility information"
446446
if (output_type == 'latex') {
447447
448448
# format nicely for PDF with kable and kableExtra
449-
my_session_info$packages_table %>%
449+
my_session_info$packages_table |>
450450
kable(
451451
booktabs = TRUE, linesep = "", caption = tbl_caption, longtable = TRUE
452-
) %>%
452+
) |>
453453
kable_styling(
454454
latex_options = 'repeat_header',
455455
repeat_header_method = 'replace'
@@ -458,8 +458,8 @@ if (output_type == 'latex') {
458458
} else {
459459
460460
# format nicely for Word with flextable
461-
my_session_info$packages_table %>%
462-
flextable() %>%
461+
my_session_info$packages_table |>
462+
flextable() |>
463463
set_caption(tbl_caption)
464464
465465
}

man/set_pandoc_markup.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)