| Title: | A Certe R Package for Miscellaneous Functions |
|---|---|
| Description: | A Certe R Package for miscellaneous functions that do not fit a dedicated package. This package also mitigates the 'vctrs' package by allowing numeric-character coercions. This package is part of the 'certedata' universe. |
| Authors: | Matthijs S. Berends [aut, cre], Erwin E. A. Hassing [aut], Erwin Dijkstra [aut], Certe Medical Diagnostics & Advice Foundation [cph, fnd] |
| Maintainer: | Matthijs S. Berends <[email protected]> |
| License: | GPL-2 |
| Version: | 1.23.5 |
| Built: | 2026-05-30 09:10:57 UTC |
| Source: | https://github.com/certe-medical-epidemiology/certetoolbox |
Download properties from the AGB Register.
agb_property(agb_code, property = NULL)agb_property(agb_code, property = NULL)
agb_code |
AGB codes |
property |
property of the AGB code. Will return a data.frame if left blank. |
The AGB (Algemeen GegevensBeheer) register is a national database in the Netherlands that assigns a unique AGB code to healthcare providers and institutions. This code is used for identification and administration within the healthcare sector, such as for billing insurance companies, contracting, and data exchange between healthcare providers.
The AGB code is managed by VECOZO and plays a crucial role in ensuring transparency and efficiency in Dutch healthcare administration.
## Not run: agb_property(03033048) agb_property(c(03033048, 01102504)) agb_property(03033048, property = "last_name") agb_property(c(03033048, 01102504), "specialty") ## End(Not run)## Not run: agb_property(03033048) agb_property(c(03033048, 01102504)) agb_property(03033048, property = "last_name") agb_property(c(03033048, 01102504), "specialty") ## End(Not run)
Uploads a local file to the AMRZNN dashboard data repository via the GitHub Contents API. Creates the file if it does not yet exist, or overwrites it if it does. No local git installation or repository clone is required.
amrznn_upload( local_file, repo_path, pat = gh::gh_token(), commit_message = paste("Automated upload:", Sys.Date()), repo = "AMRZNN/dashboard_data", verbose = TRUE )amrznn_upload( local_file, repo_path, pat = gh::gh_token(), commit_message = paste("Automated upload:", Sys.Date()), repo = "AMRZNN/dashboard_data", verbose = TRUE )
local_file |
Path to the local file to upload. |
repo_path |
Target path within the repository, e.g. |
pat |
A GitHub Personal Access Token (PAT) with |
commit_message |
Commit message to use. Defaults to |
repo |
Target repository in |
verbose |
If |
Script taken from https://github.com/AMRZNN/dashboard_data/blob/9c7b65857f5467713fc3e3b01a5c7d4f1144b961/upload_script.R.
Invisibly returns the HTTP status code of the PUT response (200 for update, 201 for new file).
## Not run: amrznn_upload( local_file = "output/weekly_resistance.csv", repo_path = "certe/weekly_resistance.csv" ) ## End(Not run)## Not run: amrznn_upload( local_file = "output/weekly_resistance.csv", repo_path = "certe/weekly_resistance.csv" ) ## End(Not run)
The as_excel() function relies on the openxlsx2 package for creating an Excel Workbook object in R. These objects can be saved using save_excel() or export_xlsx().
as_excel( ..., sheet_names = NULL, autofilter = TRUE, autowidth = TRUE, widths = NULL, rows_zebra = TRUE, cols_zebra = FALSE, freeze_top_row = TRUE, digits = 2, align = "center", table_style = "TableStyleMedium2", creator = Sys.info()["user"], department = read_secret("department.name"), project_number = project_get_current_id(ask = FALSE) ) save_excel(xl, filename = NULL, overwrite = FALSE)as_excel( ..., sheet_names = NULL, autofilter = TRUE, autowidth = TRUE, widths = NULL, rows_zebra = TRUE, cols_zebra = FALSE, freeze_top_row = TRUE, digits = 2, align = "center", table_style = "TableStyleMedium2", creator = Sys.info()["user"], department = read_secret("department.name"), project_number = project_get_current_id(ask = FALSE) ) save_excel(xl, filename = NULL, overwrite = FALSE)
... |
data sets, use named items for multiple tabs (see Examples) |
sheet_names |
sheet names |
autofilter |
create autofilter on columns in first row. This can also be a vector with the same length as |
autowidth |
automatically adjust columns widths. This can also be a vector with the same length as |
widths |
width of columns, must be length 1 or |
rows_zebra |
create banded rows. This can also be a vector with the same length as |
cols_zebra |
create banded columns. This can also be a vector with the same length as |
freeze_top_row |
freeze the first row of the sheet. This can also be a vector with the same length as |
digits |
number of digits for numeric values (integer values will always be rounded to whole numbers), defaults to |
align |
horizontal alignment of text |
table_style |
style(s) for each table, see below. This can also be a vector with the same length as |
creator |
name of the creator of the workbook |
department |
name of the department of the workbook |
project_number |
project number, to add project ID as the subject of the workbook |
xl |
Excel object, as created with |
filename |
file location to save Excel document to, defaults to a random filename in the current folder |
overwrite |
overwrite existing file |
For the argument table_style, use one or more of these table styles as character input. The default is TableStyleMedium2.
# creates a Workbook object xl <- as_excel("this is a sheet" = mtcars, "another sheet" = anscombe) xl # then save it with save_excel() or export_xlsx()# creates a Workbook object xl <- as_excel("this is a sheet" = mtcars, "another sheet" = anscombe) xl # then save it with save_excel() or export_xlsx()
Force Time as UTC
as.UTC(x, ...) ## S3 method for class 'data.frame' as.UTC(x, ...) ## S3 method for class 'POSIXct' as.UTC(x, ...) ## Default S3 method: as.UTC(x, ...)as.UTC(x, ...) ## S3 method for class 'data.frame' as.UTC(x, ...) ## S3 method for class 'POSIXct' as.UTC(x, ...) ## Default S3 method: as.UTC(x, ...)
x |
a vector of datetime values |
... |
not used at the moment |
Sys.time() as.UTC(Sys.time())Sys.time() as.UTC(Sys.time())
This function transforms a data.frame by guessing the right data classes and applying them, using readr::parse_guess() and cleaner functions such as cleaner::clean_Date().
auto_transform( x, datenames = "en", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "Europe/Amsterdam", na = c("", "NULL", "NA", "<NA>"), snake_case = FALSE, ... )auto_transform( x, datenames = "en", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "Europe/Amsterdam", na = c("", "NULL", "NA", "<NA>"), snake_case = FALSE, ... )
x |
|
datenames |
language of the date names, such as weekdays and months |
dateformat |
expected date format, will be coerced with |
timeformat |
expected time format, will be coerced with |
decimal.mark |
separator for decimal numbers |
big.mark |
separator for thousands |
timezone |
time zone to apply to all |
na |
values to interpret as |
snake_case |
apply snake case to the column names |
... |
not used as the time, allows for future extension |
Download data from CBS Open data Statline.
cbs_topics() cbs_search(topic, max_print = 25) cbs_download(identifier, clean_cols = TRUE) cbs_moreinfo(identifier)cbs_topics() cbs_search(topic, max_print = 25) cbs_download(identifier, clean_cols = TRUE) cbs_moreinfo(identifier)
topic |
topics to search for |
max_print |
maximum number of subjects to print |
identifier |
tracking number (1 to |
clean_cols |
Clean column names. |
cbs_topics() retrieves all topics.
cbs_search() searches for a specific subject.
cbs_download() downloads tables. Input has to be a CBS Identifier (printed in red in cbs_search()), or a tracking number of cbs_search(), or the result of cbs_search().
cbs_moreinfo() gives a detailed explanation for the table. Input can also be a dataset downloaded with cbs_download().
## Not run: cbs_search("Inwoners") x <- cbs_download(2) # 2nd hit of cbs_search() str(x) cbs_moreinfo(x) cbs_moreinfo(2) ## End(Not run)## Not run: cbs_search("Inwoners") x <- cbs_download(2) # 2nd hit of cbs_search() str(x) cbs_moreinfo(x) cbs_moreinfo(2) ## End(Not run)
The concat() function is at default identical to paste(c(...), sep = "", collapse = "").
The collapse() function is at default identical to paste(x, sep = "", collapse = "").
concat(..., sep = "") collapse(x, sep = "")concat(..., sep = "") collapse(x, sep = "")
..., x
|
element(s) to be pasted together, can also be vectors |
sep |
separator character, will also be used for collapsing |
concat("a", "b", "c") concat(c("a", "b"), "c") collapse(c("a", "b"), "c") concat(letters[1:5], "-") collapse(letters[1:5], "-")concat("a", "b", "c") concat(c("a", "b"), "c") collapse(c("a", "b"), "c") concat(letters[1:5], "-") collapse(letters[1:5], "-")
Transform a data set into an n x m table, e.g. to be used in certestats::confusion_matrix().
crosstab( df, identifier, compare, outcome, positive = "^pos.*", negative = "^neg.*", ..., na.rm = TRUE, ignore_case = TRUE )crosstab( df, identifier, compare, outcome, positive = "^pos.*", negative = "^neg.*", ..., na.rm = TRUE, ignore_case = TRUE )
df |
|
identifier |
a column name to use as identifier, such as a patient ID or an order ID |
compare |
a column name for the two axes of the table: the labels between the outcomes must be compared |
outcome |
a column name containing the outcome values to compare |
positive |
a stringr::regex to match the values in |
negative |
a stringr::regex to match the values in |
... |
manual stringr::regexes for classes if not using |
na.rm |
a logical to indicate whether empty values must be removed before forming the table |
ignore_case |
a logical to indicate whether the case in the values of |
df <- data.frame( order_nr = sort(rep(LETTERS[1:20], 2)), test_type = rep(c("Culture", "PCR"), 20), result = sample(c("pos", "neg"), size = 40, replace = TRUE, prob = c(0.3, 0.9)) ) head(df) out <- df |> crosstab(order_nr, test_type, result) out df$result <- gsub("pos", "#p", df$result) df$result <- gsub("neg", "#n", df$result) head(df) # gives a warning that pattern matching failed: df |> crosstab(order_nr, test_type, result) # define the pattern yourself in such case: df |> crosstab(order_nr, test_type, result, positive = "#p", negative = "#n") # defining classes manually, can be more than 2: df |> crosstab(order_nr, test_type, result, ClassA = "#p", Hello = "#n") if ("certestats" %in% rownames(utils::installed.packages())) { certestats::confusion_matrix(out) }df <- data.frame( order_nr = sort(rep(LETTERS[1:20], 2)), test_type = rep(c("Culture", "PCR"), 20), result = sample(c("pos", "neg"), size = 40, replace = TRUE, prob = c(0.3, 0.9)) ) head(df) out <- df |> crosstab(order_nr, test_type, result) out df$result <- gsub("pos", "#p", df$result) df$result <- gsub("neg", "#n", df$result) head(df) # gives a warning that pattern matching failed: df |> crosstab(order_nr, test_type, result) # define the pattern yourself in such case: df |> crosstab(order_nr, test_type, result, positive = "#p", negative = "#n") # defining classes manually, can be more than 2: df |> crosstab(order_nr, test_type, result, ClassA = "#p", Hello = "#n") if ("certestats" %in% rownames(utils::installed.packages())) { certestats::confusion_matrix(out) }
These are convenience functions to get certain dates relatively to today.
yesterday(ref = today()) tomorrow(ref = today()) week(ref = today()) year(ref = today()) last_week(ref = today(), only_start_end = FALSE) this_week(ref = today(), only_start_end = FALSE) next_week(ref = today(), only_start_end = FALSE) last_month(ref = today(), only_start_end = FALSE) this_month(ref = today(), only_start_end = FALSE) next_month(ref = today(), only_start_end = FALSE) last_quarter(ref = today(), only_start_end = FALSE) this_quarter(ref = today(), only_start_end = FALSE) next_quarter(ref = today(), only_start_end = FALSE) last_year(ref = today(), only_start_end = FALSE) this_year(ref = today(), only_start_end = FALSE) next_year(ref = today(), only_start_end = FALSE) last_n_years(n, ref = end_of_last_year(), only_start_end = FALSE) last_5_years(ref = end_of_last_year(), only_start_end = FALSE) last_10_years(ref = end_of_last_year(), only_start_end = FALSE) last_n_months(n, ref = end_of_last_month(), only_start_end = FALSE) last_3_months(ref = end_of_last_month(), only_start_end = FALSE) last_6_months(ref = end_of_last_month(), only_start_end = FALSE) last_n_weeks(n, ref = end_of_last_week(), only_start_end = FALSE) year_to_date(ref = today(), only_start_end = FALSE) year_since_date(ref = today(), only_start_end = FALSE) start_of_last_week(ref = today()) end_of_last_week(ref = today()) start_of_this_week(ref = today()) end_of_this_week(ref = today()) start_of_last_month(ref = today()) end_of_last_month(ref = today()) start_of_this_month(ref = today()) end_of_this_month(ref = today()) start_of_next_month(ref = today()) end_of_next_month(ref = today()) start_of_last_quarter(ref = today()) end_of_last_quarter(ref = today()) start_of_this_quarter(ref = today()) end_of_this_quarter(ref = today()) start_of_next_quarter(ref = today()) end_of_next_quarter(ref = today()) start_of_last_year(ref = today()) end_of_last_year(ref = today()) start_of_this_year(ref = today()) end_of_this_year(ref = today()) start_of_next_year(ref = today()) end_of_next_year(ref = today()) nth_monday(ref = today(), n = 1) nth_tuesday(ref = today(), n = 1) nth_wednesday(ref = today(), n = 1) nth_thursday(ref = today(), n = 1) nth_friday(ref = today(), n = 1) nth_saturday(ref = today(), n = 1) nth_sunday(ref = today(), n = 1) week2date(wk, yr = year(today()), day = 1) week2resp_season(wk, remove_outside_season = FALSE)yesterday(ref = today()) tomorrow(ref = today()) week(ref = today()) year(ref = today()) last_week(ref = today(), only_start_end = FALSE) this_week(ref = today(), only_start_end = FALSE) next_week(ref = today(), only_start_end = FALSE) last_month(ref = today(), only_start_end = FALSE) this_month(ref = today(), only_start_end = FALSE) next_month(ref = today(), only_start_end = FALSE) last_quarter(ref = today(), only_start_end = FALSE) this_quarter(ref = today(), only_start_end = FALSE) next_quarter(ref = today(), only_start_end = FALSE) last_year(ref = today(), only_start_end = FALSE) this_year(ref = today(), only_start_end = FALSE) next_year(ref = today(), only_start_end = FALSE) last_n_years(n, ref = end_of_last_year(), only_start_end = FALSE) last_5_years(ref = end_of_last_year(), only_start_end = FALSE) last_10_years(ref = end_of_last_year(), only_start_end = FALSE) last_n_months(n, ref = end_of_last_month(), only_start_end = FALSE) last_3_months(ref = end_of_last_month(), only_start_end = FALSE) last_6_months(ref = end_of_last_month(), only_start_end = FALSE) last_n_weeks(n, ref = end_of_last_week(), only_start_end = FALSE) year_to_date(ref = today(), only_start_end = FALSE) year_since_date(ref = today(), only_start_end = FALSE) start_of_last_week(ref = today()) end_of_last_week(ref = today()) start_of_this_week(ref = today()) end_of_this_week(ref = today()) start_of_last_month(ref = today()) end_of_last_month(ref = today()) start_of_this_month(ref = today()) end_of_this_month(ref = today()) start_of_next_month(ref = today()) end_of_next_month(ref = today()) start_of_last_quarter(ref = today()) end_of_last_quarter(ref = today()) start_of_this_quarter(ref = today()) end_of_this_quarter(ref = today()) start_of_next_quarter(ref = today()) end_of_next_quarter(ref = today()) start_of_last_year(ref = today()) end_of_last_year(ref = today()) start_of_this_year(ref = today()) end_of_this_year(ref = today()) start_of_next_year(ref = today()) end_of_next_year(ref = today()) nth_monday(ref = today(), n = 1) nth_tuesday(ref = today(), n = 1) nth_wednesday(ref = today(), n = 1) nth_thursday(ref = today(), n = 1) nth_friday(ref = today(), n = 1) nth_saturday(ref = today(), n = 1) nth_sunday(ref = today(), n = 1) week2date(wk, yr = year(today()), day = 1) week2resp_season(wk, remove_outside_season = FALSE)
ref |
reference date (defaults to today) |
only_start_end |
logical to indicate whether only the first and last value of the resulting vector should be returned |
n |
relative number of weeks |
wk |
week to search for |
yr |
year to search for, defaults to current year |
day |
day to return (0 are 7 are Sunday, 1 is Monday, etc.) |
remove_outside_season |
a logical to remove week numbers in the range 21-39 |
All functions return a vector of dates, except for yesterday(), today(), tomorrow(), week2date(), and the start_of_*(), end_of_*() and nth_*() functions; these return 1 date.
Week ranges always start on Mondays and end on Sundays.
year() always returns an integer.
The last_n_years(), last_5_years() and last_10_years() functions have their reference date set to end_of_last_year() at default.
The last_n_months(), last_3_months() and last_6_months() functions have their reference date set to end_of_last_month() at default.
The last_n_weeks() function has its reference date set to end_of_last_week() at default.
week2resp_season() transforms week numbers to an ordered factor, in a range 40-53, 1:39 (or, if remove_outside_season = TRUE, 40-53, 1:20). This function is useful for plotting.
today() today() %in% this_month() next_week() next_week(only_start_end = TRUE) # 2nd Monday of last month: last_month() |> nth_monday(2) # last_*_years() will have 1 Jan to 31 Dec at default: last_5_years(only_start_end = TRUE) last_5_years(today(), only_start_end = TRUE) last_3_months(only_start_end = TRUE) year_to_date(only_start_end = TRUE) ## Not run: # great for certedb functions: certedb::get_diver_data(last_5_years(), Bepaling == "ACBDE") ## End(Not run) df <- data.frame(date = sample(seq.Date(start_of_last_year(), end_of_this_year(), by = "day"), size = 500)) df$time <- as.POSIXct(paste(df$date, "12:00:00")) library(dplyr, warn.conflicts = FALSE) # these are equal: df |> filter(date |> between(start_of_last_week(), end_of_last_week())) df |> filter(date %in% last_week()) # but this does not work: df |> filter(time %in% last_week()) # so be sure to transform times to dates in certain filters df |> filter(as.Date(time) %in% last_week())today() today() %in% this_month() next_week() next_week(only_start_end = TRUE) # 2nd Monday of last month: last_month() |> nth_monday(2) # last_*_years() will have 1 Jan to 31 Dec at default: last_5_years(only_start_end = TRUE) last_5_years(today(), only_start_end = TRUE) last_3_months(only_start_end = TRUE) year_to_date(only_start_end = TRUE) ## Not run: # great for certedb functions: certedb::get_diver_data(last_5_years(), Bepaling == "ACBDE") ## End(Not run) df <- data.frame(date = sample(seq.Date(start_of_last_year(), end_of_this_year(), by = "day"), size = 500)) df$time <- as.POSIXct(paste(df$date, "12:00:00")) library(dplyr, warn.conflicts = FALSE) # these are equal: df |> filter(date |> between(start_of_last_week(), end_of_last_week())) df |> filter(date %in% last_week()) # but this does not work: df |> filter(time %in% last_week()) # so be sure to transform times to dates in certain filters df |> filter(as.Date(time) %in% last_week())
These functions can be used to export data sets and plots. They invisibly return the object itself again, allowing for usage in pipes (except for the plot-exporting functions export_pdf(), export_png() and export_html()). The functions work closely together with the certeprojects package to support Microsoft Planner project numbers.
export( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, encrypt = !is.null(filename) && filename %like% "[.]rds$", key = read_secret("tools.encryption_password"), fn = NULL, ... ) export_rds( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, encrypt = TRUE, key = read_secret("tools.encryption_password"), ... ) export_xlsx( ..., filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, sheet_names = NULL, autofilter = TRUE, rows_zebra = TRUE, cols_zebra = FALSE, freeze_top_row = TRUE, table_style = "TableStyleMedium2", align = "center" ) export_excel( ..., filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, sheet_names = NULL, autofilter = TRUE, rows_zebra = TRUE, cols_zebra = FALSE, freeze_top_row = TRUE, table_style = "TableStyleMedium2", align = "center" ) export_csv( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, na = "", ... ) export_csv2( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, na = "", ... ) export_tsv( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, na = "", ... ) export_txt( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, sep = "\t", na = "", ... ) export_sav( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, ... ) export_spss( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, ... ) export_feather( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, ... ) export_parquet( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, ... ) export_pdf( plot, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, size = "A5", portrait = FALSE, ... ) export_png( plot, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, width = 1000, height = 800, dpi = NULL, ... ) export_html( plot, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, ... ) encrypt_object( object, key = read_secret("tools.encryption_password"), serialise = TRUE, compress = TRUE ) export_clipboard( object, sep = "\t", na = "", header = TRUE, quote = FALSE, decimal.mark = dec_mark(), ... ) export_teams( object, filename = NULL, full_teams_path = NULL, account = connect_teams(), ... )export( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, encrypt = !is.null(filename) && filename %like% "[.]rds$", key = read_secret("tools.encryption_password"), fn = NULL, ... ) export_rds( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, encrypt = TRUE, key = read_secret("tools.encryption_password"), ... ) export_xlsx( ..., filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, sheet_names = NULL, autofilter = TRUE, rows_zebra = TRUE, cols_zebra = FALSE, freeze_top_row = TRUE, table_style = "TableStyleMedium2", align = "center" ) export_excel( ..., filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, sheet_names = NULL, autofilter = TRUE, rows_zebra = TRUE, cols_zebra = FALSE, freeze_top_row = TRUE, table_style = "TableStyleMedium2", align = "center" ) export_csv( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, na = "", ... ) export_csv2( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, na = "", ... ) export_tsv( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, na = "", ... ) export_txt( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, sep = "\t", na = "", ... ) export_sav( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, ... ) export_spss( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, ... ) export_feather( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, ... ) export_parquet( object, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, ... ) export_pdf( plot, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, size = "A5", portrait = FALSE, ... ) export_png( plot, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, width = 1000, height = 800, dpi = NULL, ... ) export_html( plot, filename = NULL, project_number = project_get_current_id(ask = FALSE), overwrite = NULL, ... ) encrypt_object( object, key = read_secret("tools.encryption_password"), serialise = TRUE, compress = TRUE ) export_clipboard( object, sep = "\t", na = "", header = TRUE, quote = FALSE, decimal.mark = dec_mark(), ... ) export_teams( object, filename = NULL, full_teams_path = NULL, account = connect_teams(), ... )
object, plot
|
the R object to export |
filename |
the full path of the exported file |
project_number |
a Microsoft Planner project number |
overwrite |
a logical value to indicate if an existing file must be overwritten. In interactive mode, this will be asked if the file exists. In non-interactive mode, this has a special default behaviour: the original file will be copied to |
encrypt |
a logical value to indicate if the object must be encrypted before exporting using AES-GCM via |
key |
a character to be used as the encryption key. Internally, this is converted using |
fn |
a manual export function, such as |
... |
arguments passed on to methods |
sheet_names |
sheet names |
autofilter |
create autofilter on columns in first row. This can also be a vector with the same length as |
rows_zebra |
create banded rows. This can also be a vector with the same length as |
cols_zebra |
create banded columns. This can also be a vector with the same length as |
freeze_top_row |
freeze the first row of the sheet. This can also be a vector with the same length as |
table_style |
style(s) for each table, see below. This can also be a vector with the same length as |
align |
horizontal alignment of text |
na |
replacement character for empty values (default: |
sep |
separator for values in a row (default: tab) |
size |
paper size, defaults to A5. Can be A0 to A7. |
portrait |
portrait mode, defaults to |
width |
required width of the PNG file in pixels |
height |
required height of the PNG file in pixels |
dpi |
plot resolution, defaults to DPI set in |
serialise |
whether object must be serialised |
compress |
whether object must be compressed |
header |
(for |
quote |
(for |
decimal.mark |
(for |
full_teams_path |
path in Teams to export object to. Can be left blank to use interactive folder picking mode in the console. |
account |
a Teams account from Azure or an |
The export() function can export to any file format, also with a manually set export function when passed on to the fn argument. This function fn has to have the object as first argument and the future file location as second argument. If fn is left blank, the export_* function will be used based on the filename.
RDS files as created using export_rds() are compatible with R3 and R4.
The export_xlsx() and export_excel() functions use save_excel(as_excel(...)) internally. IMPORTANT: these two functions can accept more than one data.frame. When naming the data sets, the names will become sheet names in the resulting Excel file. For a complete visual overview of supported table styles, see as_excel(). If the last value in ... is a character of length 1 and filename is NULL, this value is assumed to be the filename.
For export_csv(), export_csv2() and export_tsv(), files will be saved in UTF-8 encoding and NA values will be exported as "" at default. Like other *.csv and *.csv2 functions, csv is comma (,) separated and csv2 is semicolon (;) separated.
The export_txt() function exports to a tab-separated file.
Exporting to an SPSS file using export_sav() or export_spss() requires the haven package to be installed.
Exporting to a Feather file using export_feather() requires the arrow package to be installed. Apache Feather provides efficient binary columnar serialization for data sets, enabling easy sharing data across data analysis languages (such as between Python and R).
Exporting to a Parquet file using export_parquet() requires the arrow package to be installed. Apache Parquet is an open source, column-oriented data file format designed for efficient data storage and retrieval.
Exporting to a PDF file using export_pdf() requires the ggplot2 package to be installed. If the filename is left blank in export_pdf(), export_png() or export_html(), the title of plot will be used if it's available and the certeplot2 package is installed, and a timestamp otherwise. NOTE: All export functions invisibly return object again, but the plotting functions invisibly return the file path
Exporting to a PNG file using export_png() requires the ggplot2 and showtext packages to be installed.
Exporting to an HTML file using export_html() requires the ggplot2 and htmltools packages to be installed. The arguments put in ... will be passed on to plotly::layout() if plot is not yet a Plotly object (but rather a ggplot2 object), which of course then requires the plotly package to be installed as well.
Exporting to the clipboard using export_clipboard() requires the clipr package to be installed. The function allows any object (also other than data.frames) to be exported to the clipboard and is only limited to the available amount of RAM memory.
Exporting to Microsoft Teams using export_teams() requires the AzureGraph package to be installed. The function allows any object (also other than data.frames) to be exported to any Team channel. The filename set in filename will determine the exported file type and defaults to an RDS file.
library(dplyr, warn.conflicts = FALSE) # export to two files: 'whole_file.rds' and 'first_ten_rows.xlsx' starwars |> export_rds("whole_file") |> slice(1:10) |> export_xlsx("first_ten_rows") # the above is equal to: # starwars |> # export("whole_file.rds") |> # slice(1:10) |> # export("first_ten_rows.xlsx") # RDS files are encrypted by default x <- base::readRDS("whole_file.rds") head(x) # use decrypt_object() for manual decryption x <- decrypt_object(x) head(x) # this goes automatically with import_rds(): x <- import_rds("whole_file.rds") head(x) # Apache's Feather format is column-based # and allow for cross-language specific and fast file reading starwars |> export_feather() import("starwars.feather", col_select = starts_with("h")) |> head() # (cleanup) file.remove("whole_file.rds") file.remove("first_ten_rows.xlsx") file.remove("starwars.feather") ## Not run: # ---- Microsoft Teams support ------------------------------------------- # IMPORTING # import from Teams by picking a folder interactively from any Team x <- import_teams() # to NOT pick a Teams folder (e.g. in non-interactive mode), set `full_teams_path` x <- import_teams(full_teams_path = "MyTeam/MyChannel/MyFolder/MyFile.xlsx") # EXPORTING # export to Teams by picking a folder interactively from any Team mtcars |> export_teams() # the default is RDS, but you can set `filename` to specify yourself mtcars |> export_teams("mtcars.xlsx") # to NOT pick a Teams folder (e.g. in non-interactive mode), set `full_teams_path` mtcars |> export_teams("mtcars.xlsx", full_teams_path = "MyTeam/MyChannel/MyFolder") mtcars |> export_teams(full_teams_path = "MyTeam/MyChannel/MyFolder") ## End(Not run)library(dplyr, warn.conflicts = FALSE) # export to two files: 'whole_file.rds' and 'first_ten_rows.xlsx' starwars |> export_rds("whole_file") |> slice(1:10) |> export_xlsx("first_ten_rows") # the above is equal to: # starwars |> # export("whole_file.rds") |> # slice(1:10) |> # export("first_ten_rows.xlsx") # RDS files are encrypted by default x <- base::readRDS("whole_file.rds") head(x) # use decrypt_object() for manual decryption x <- decrypt_object(x) head(x) # this goes automatically with import_rds(): x <- import_rds("whole_file.rds") head(x) # Apache's Feather format is column-based # and allow for cross-language specific and fast file reading starwars |> export_feather() import("starwars.feather", col_select = starts_with("h")) |> head() # (cleanup) file.remove("whole_file.rds") file.remove("first_ten_rows.xlsx") file.remove("starwars.feather") ## Not run: # ---- Microsoft Teams support ------------------------------------------- # IMPORTING # import from Teams by picking a folder interactively from any Team x <- import_teams() # to NOT pick a Teams folder (e.g. in non-interactive mode), set `full_teams_path` x <- import_teams(full_teams_path = "MyTeam/MyChannel/MyFolder/MyFile.xlsx") # EXPORTING # export to Teams by picking a folder interactively from any Team mtcars |> export_teams() # the default is RDS, but you can set `filename` to specify yourself mtcars |> export_teams("mtcars.xlsx") # to NOT pick a Teams folder (e.g. in non-interactive mode), set `full_teams_path` mtcars |> export_teams("mtcars.xlsx", full_teams_path = "MyTeam/MyChannel/MyFolder") mtcars |> export_teams(full_teams_path = "MyTeam/MyChannel/MyFolder") ## End(Not run)
Generates hashes with or without an extra key/salt. This key defaults to the project identifier.
generate_hash(x, key = TRUE, bits = 256)generate_hash(x, key = TRUE, bits = 256)
x |
input, will be converted to character |
key |
key or salt. Use |
bits |
number of bits, often one of: 224, 256, 384, 512 |
This function uses the openssl::sha2() function for the hashing, but always returns a character vector.
generate_hash("a") generate_hash(c("a", "b", "c")) generate_hash("a", "secret") generate_hash(c("a", "b", "c"), "secret")generate_hash("a") generate_hash(c("a", "b", "c")) generate_hash("a", "secret") generate_hash(c("a", "b", "c"), "secret")
This function creates unique identifier (IDs) using sample().
generate_identifier(id_length = 6, n = 1, chars = c(0:9, letters[1:6]))generate_identifier(id_length = 6, n = 1, chars = c(0:9, letters[1:6]))
id_length |
character length of ID |
n |
number of IDs to generate |
chars |
characters to use for generation, defaults to hexadecimal characters (0-9 and a-f) |
generate_identifier(8) generate_identifier(6, 3)generate_identifier(8) generate_identifier(6, 3)
Hospitalname and/or location, with support for all hospitals in Northern Netherlands, including Meppel, Hardenberg and Zwolle.
hospital_name(x, format = "{naamkort}, {plaats}")hospital_name(x, format = "{naamkort}, {plaats}")
x |
text to be transformed |
format |
default is |
hospital_name(c("MCL", "MCL", "Martini")) hospital_name(c("Antonius", "WZA", "Martini"), format = "{naam} te {plaats}") # special case for GGD hospital_name(c("Martini", "GGD Groningen", "GGD Drenthe"), format = "{naam}") hospital_name(c("Martini", "GGD Groningen", "GGD Drenthe"), format = "{naamkort}") hospital_name("ggd friesland", "{naam}")hospital_name(c("MCL", "MCL", "Martini")) hospital_name(c("Antonius", "WZA", "Martini"), format = "{naam} te {plaats}") # special case for GGD hospital_name(c("Martini", "GGD Groningen", "GGD Drenthe"), format = "{naam}") hospital_name(c("Martini", "GGD Groningen", "GGD Drenthe"), format = "{naamkort}") hospital_name("ggd friesland", "{naam}")
These functions can be used to import data, from local or remote paths, or from the internet. They work closely with the certeprojects package to support Microsoft Planner project numbers. To support row names and older R versions, import_*() functions return plain data.frames, not e.g. tibbles.
import( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, encoding = "UTF-8", key = read_secret("tools.encryption_password"), ... ) import_rds( filename, project_number = project_get_current_id(ask = FALSE), key = read_secret("tools.encryption_password"), ... ) readRDS( filename, project_number = project_get_current_id(ask = FALSE), key = read_secret("tools.encryption_password"), ... ) import_xlsx( filename, project_number = project_get_current_id(ask = FALSE), sheet = 1, range = NULL, auto_transform = TRUE, datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = dec_mark(), big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, ... ) import_excel( filename, project_number = project_get_current_id(ask = FALSE), sheet = 1, range = NULL, auto_transform = TRUE, datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = dec_mark(), big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, ... ) import_csv( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, encoding = "UTF-8", ... ) import_csv2( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ",", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, encoding = "UTF-8", ... ) import_tsv( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, encoding = "UTF-8", ... ) import_txt( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, sep = "\t", datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ",", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, encoding = "UTF-8", ... ) import_sav( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, datenames = "en", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), ... ) import_spss( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, datenames = "en", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), ... ) import_feather( filename, project_number = project_get_current_id(ask = FALSE), col_select = everything(), ... ) decrypt_object( object, key = read_secret("tools.encryption_password"), serialised = TRUE, compressed = TRUE ) import_parquet( filename, project_number = project_get_current_id(ask = FALSE), col_select = everything(), ... ) import_clipboard( sep = "\t", header = TRUE, startrow = 1, auto_transform = TRUE, datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = dec_mark(), big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), ... ) import_mail_attachment( search = "hasattachment:yes", search_subject = NULL, search_from = NULL, search_when = NULL, search_attachment = NULL, folder = certemail::get_inbox_name(account = account), n = 5, sort = "received desc", account = certemail::connect_outlook(), auto_transform = TRUE, sep = ",", ... ) import_url( url, auto_transform = TRUE, sep = ",", datenames = "en", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, encoding = "UTF-8", ... ) import_teams( full_teams_path = NULL, account = connect_teams(), auto_transform = TRUE, sep = ",", datenames = "en", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, encoding = "UTF-8" )import( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, encoding = "UTF-8", key = read_secret("tools.encryption_password"), ... ) import_rds( filename, project_number = project_get_current_id(ask = FALSE), key = read_secret("tools.encryption_password"), ... ) readRDS( filename, project_number = project_get_current_id(ask = FALSE), key = read_secret("tools.encryption_password"), ... ) import_xlsx( filename, project_number = project_get_current_id(ask = FALSE), sheet = 1, range = NULL, auto_transform = TRUE, datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = dec_mark(), big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, ... ) import_excel( filename, project_number = project_get_current_id(ask = FALSE), sheet = 1, range = NULL, auto_transform = TRUE, datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = dec_mark(), big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, ... ) import_csv( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, encoding = "UTF-8", ... ) import_csv2( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ",", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, encoding = "UTF-8", ... ) import_tsv( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, encoding = "UTF-8", ... ) import_txt( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, sep = "\t", datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ",", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, encoding = "UTF-8", ... ) import_sav( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, datenames = "en", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), ... ) import_spss( filename, project_number = project_get_current_id(ask = FALSE), auto_transform = TRUE, datenames = "en", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), ... ) import_feather( filename, project_number = project_get_current_id(ask = FALSE), col_select = everything(), ... ) decrypt_object( object, key = read_secret("tools.encryption_password"), serialised = TRUE, compressed = TRUE ) import_parquet( filename, project_number = project_get_current_id(ask = FALSE), col_select = everything(), ... ) import_clipboard( sep = "\t", header = TRUE, startrow = 1, auto_transform = TRUE, datenames = "nl", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = dec_mark(), big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), ... ) import_mail_attachment( search = "hasattachment:yes", search_subject = NULL, search_from = NULL, search_when = NULL, search_attachment = NULL, folder = certemail::get_inbox_name(account = account), n = 5, sort = "received desc", account = certemail::connect_outlook(), auto_transform = TRUE, sep = ",", ... ) import_url( url, auto_transform = TRUE, sep = ",", datenames = "en", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, encoding = "UTF-8", ... ) import_teams( full_teams_path = NULL, account = connect_teams(), auto_transform = TRUE, sep = ",", datenames = "en", dateformat = "yyyy-mm-dd", timeformat = "HH:MM", decimal.mark = ".", big.mark = "", timezone = "UTC", na = c("", "NULL", "NA", "<NA>"), skip = 0, encoding = "UTF-8" )
filename |
the full path of the file to be imported, will be parsed to a character, can also be a remote location (from http/https/ftp/ssh, GitHub/GitLab) |
project_number |
a Microsoft Planner project number |
auto_transform |
transform the imported data with |
encoding |
Default encoding. This only affects how the file is read. |
key |
a character to decrypt the file, see |
... |
arguments passed on to methods |
sheet |
Excel sheet to import, defaults to first sheet |
range |
a cell range to read from, allows typical Excel ranges such as "B3:D87" and "Budget!B2:G14" |
datenames |
language of the date names, such as weekdays and months |
dateformat |
expected date format, will be coerced with |
timeformat |
expected time format, will be coerced with |
decimal.mark |
separator for decimal numbers |
big.mark |
separator for thousands |
timezone |
time zone to apply to all |
na |
values to interpret as |
skip |
number of first rows to skip |
sep |
character to separate values in a row |
col_select |
columns to select, supports the tidyselect language) |
object |
object to decrypt |
serialised |
whether object was serialised |
compressed |
whether object was compressed |
header |
use first row as header |
startrow |
first row to start importing |
search |
an ODATA filter, ignores |
search_subject |
a character, equal to |
search_from |
a character, equal to |
search_when |
a Date vector of size 1 or 2, equal to |
search_attachment |
a character to use a regular expression for attachment file names |
folder |
email folder name to search in, defaults to Inbox of the current user by calling |
n |
maximum number of emails to search |
sort |
initial sorting |
account |
a Teams account from Azure or an |
url |
remote location of any data set, can also be a (non-raw) GitHub/GitLab link |
full_teams_path |
a full path in Teams, including the Team name and the channel name. Leave blank to use interactive mode, which allows file/folder picking from a list in the console. |
Importing any unlisted filetype using import() requires the rio package to be installed.
Importing an Excel file using import_xlsx() or import_excel() requires the readxl package to be installed.
Importing an SPSS file using import_sav() or import_spss() requires the haven package to be installed.
Importing a Feather file using import_feather() requires the arrow package to be installed. Apache Feather provides efficient binary columnar serialization for data sets, enabling easy sharing data across data analysis languages (such as between Python and R). Use the col_select argument (which supports the tidyselect language) for specific data selection to improve importing speed.
Importing a Parquet file using import_parquet() requires the arrow package to be installed. Apache Parquet is an open source, column-oriented data file format designed for efficient data storage and retrieval. Use the col_select argument (which supports the tidyselect language) for specific data selection to improve importing speed.
Importing the clipboard using import_clipboard() requires the clipr package to be installed.
Importing mail attachments using import_mail_attachment() requires the certemail package to be installed. It calls download_mail_attachment() internally and saves the attachment to a temporary folder. For all folder names, run: sapply(certemail::connect_outlook()$list_folders(), function(x) x$properties$displayName).
The import_url() function tries to download the file first, after which it will be imported using the appropriate import_*() function.
The import_teams() function uses certeprojects::teams_download_file() to provide an interactive way to select a file in any Team, to download the file, and to import the file using the appropriate import_*() function.
export_csv(iris) import_csv("iris") |> head() # the above is equal to: # export(iris, "iris.csv") # import("iris.csv") |> head() # row names are also supported export_csv(mtcars) import_csv("mtcars") |> head() # Apache's Feather format is column-based # and allow for specific and fast file reading library(dplyr, warn.conflicts = FALSE) starwars |> export_feather() import("starwars.feather", col_select = starts_with("h")) |> head() # (cleanup) file.remove("iris.csv") file.remove("mtcars.csv") file.remove("starwars.feather") ## Not run: # ---- Microsoft Teams support ------------------------------------------- # IMPORTING # import from Teams by picking a folder interactively from any Team x <- import_teams() # to NOT pick a Teams folder (e.g. in non-interactive mode), set `full_teams_path` x <- import_teams(full_teams_path = "MyTeam/MyChannel/MyFolder/MyFile.xlsx") # EXPORTING # export to Teams by picking a folder interactively from any Team mtcars |> export_teams() # the default is RDS, but you can set `filename` to specify yourself mtcars |> export_teams("mtcars.xlsx") # to NOT pick a Teams folder (e.g. in non-interactive mode), set `full_teams_path` mtcars |> export_teams("mtcars.xlsx", full_teams_path = "MyTeam/MyChannel/MyFolder") mtcars |> export_teams(full_teams_path = "MyTeam/MyChannel/MyFolder") ## End(Not run)export_csv(iris) import_csv("iris") |> head() # the above is equal to: # export(iris, "iris.csv") # import("iris.csv") |> head() # row names are also supported export_csv(mtcars) import_csv("mtcars") |> head() # Apache's Feather format is column-based # and allow for specific and fast file reading library(dplyr, warn.conflicts = FALSE) starwars |> export_feather() import("starwars.feather", col_select = starts_with("h")) |> head() # (cleanup) file.remove("iris.csv") file.remove("mtcars.csv") file.remove("starwars.feather") ## Not run: # ---- Microsoft Teams support ------------------------------------------- # IMPORTING # import from Teams by picking a folder interactively from any Team x <- import_teams() # to NOT pick a Teams folder (e.g. in non-interactive mode), set `full_teams_path` x <- import_teams(full_teams_path = "MyTeam/MyChannel/MyFolder/MyFile.xlsx") # EXPORTING # export to Teams by picking a folder interactively from any Team mtcars |> export_teams() # the default is RDS, but you can set `filename` to specify yourself mtcars |> export_teams("mtcars.xlsx") # to NOT pick a Teams folder (e.g. in non-interactive mode), set `full_teams_path` mtcars |> export_teams("mtcars.xlsx", full_teams_path = "MyTeam/MyChannel/MyFolder") mtcars |> export_teams(full_teams_path = "MyTeam/MyChannel/MyFolder") ## End(Not run)
Generates a JSON representation of a dataset’s structure. Each column includes class, number of unique values, and optionally a truncated list of values unless excluded by type or pattern. All columns are retained in the output.
json_data_structure( dataset, dataset_name = NULL, n_first = 100, cols_exclude = "(bsn|id$|num[mb]er)", output_file = NULL )json_data_structure( dataset, dataset_name = NULL, n_first = 100, cols_exclude = "(bsn|id$|num[mb]er)", output_file = NULL )
dataset |
data.frame Input dataset. |
dataset_name |
Optional name of dataset, used in JSON root. |
n_first |
Maximum number of unique values to include. |
cols_exclude |
Regular expression of column names to exclude values from. |
output_file |
Output path for JSON file. |
Invisibly returns the structured list written to JSON.
Convenient wrapper around grepl() to match a pattern: x %like% pattern. It always returns a logical vector and is always case-insensitive (use x %like_case% pattern for case-sensitive matching). Also, pattern can be as long as x to compare items of each index in both vectors, or they both can have the same length to iterate over all cases.
like(x, pattern, ignore.case = TRUE) x %like% pattern x %unlike% pattern x %like_case% pattern x %unlike_case% patternlike(x, pattern, ignore.case = TRUE) x %like% pattern x %unlike% pattern x %like_case% pattern x %unlike_case% pattern
x |
a character vector where matches are sought, or an object which can be coerced by |
pattern |
a character vector containing regular expressions (or a character string for |
ignore.case |
if |
These like() and %like%/%unlike% functions:
Are case-insensitive (use %like_case%/%unlike_case% for case-sensitive matching)
Support multiple patterns
Check if pattern is a valid regular expression and sets fixed = TRUE if not, to greatly improve speed (vectorised over pattern)
Always use compatibility with Perl unless fixed = TRUE, to greatly improve speed
Using RStudio? The %like%/%unlike% functions can also be directly inserted in your code from the Addins menu and can have its own keyboard shortcut like Shift+Ctrl+L or Shift+Cmd+L (see menu Tools > Modify Keyboard Shortcuts...). If you keep pressing your shortcut, the inserted text will be iterated over %like% -> %unlike% -> %like_case% -> %unlike_case%.
A logical vector
Idea from the like function from the data.table package, although altered as explained in Details.
a <- "This is a test" b <- "TEST" a %like% b b %like% a # also supports multiple patterns a <- c("Test case", "Something different", "Yet another thing") b <- c( "case", "diff", "yet") a %like% b a %unlike% b a[1] %like% b a %like% b[1]a <- "This is a test" b <- "TEST" a %like% b b %like% a # also supports multiple patterns a <- c("Test case", "Something different", "Yet another thing") b <- c( "case", "diff", "yet") a %like% b a %unlike% b a[1] %like% b a %like% b[1]
This function is analogous to all mo_* functions of the AMR package, see AMR::mo_property().
mo_glims( x, language = AMR::get_AMR_locale(), keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ... )mo_glims( x, language = AMR::get_AMR_locale(), keep_synonyms = getOption("AMR_keep_synonyms", FALSE), ... )
x |
Any character (vector) that can be coerced to a valid microorganism code with |
language |
Language to translate text like "no growth", which defaults to the system language (see |
keep_synonyms |
A logical to indicate if outdated, previously valid taxonomic names must be preserved and not be corrected to currently accepted names. Do note that the term "synonym" is in this case jargon from the field of microbial taxonomy - it is not in place to denote that e.g. "Streptococcus Group A" is a synonym of S. pyogenes. Though this is practically the case, taxonomically it is not as "Streptococcus Group A" is not even a valid taxonomic name. The default is |
... |
Other arguments passed on to |
mo_glims("E. coli") library(dplyr, warn.conflicts = FALSE) data.frame(mo = c("ESCCOL", "Staph aureus")) |> mutate(glims = mo_glims()) # even works for non-existing entries in AMR package mo_glims("Streptococcus mitis/oralis") if (require(AMR, warn.conflicts = FALSE)) { as.mo("Streptococcus mitis/oralis") } if (require("AMR")) { mo_genus("Streptococcus mitis/oralis") } if (require("AMR")) { mo_gramstain("Streptococcus mitis/oralis") }mo_glims("E. coli") library(dplyr, warn.conflicts = FALSE) data.frame(mo = c("ESCCOL", "Staph aureus")) |> mutate(glims = mo_glims()) # even works for non-existing entries in AMR package mo_glims("Streptococcus mitis/oralis") if (require(AMR, warn.conflicts = FALSE)) { as.mo("Streptococcus mitis/oralis") } if (require("AMR")) { mo_genus("Streptococcus mitis/oralis") } if (require("AMR")) { mo_gramstain("Streptococcus mitis/oralis") }
%in%
Default in R >= 4.6.0.
x %notin% tablex %notin% table
x |
vector or |
table |
vector or |
P-symbol format as asterisk
p_symbol(p, emptychar = " ")p_symbol(p, emptychar = " ")
p |
numeric value between 0 and 1 |
emptychar |
sign to be displayed for 0.1 < p < 1.0 |
Securely transfer any R object with full attribute preservation and cross-platform JSON compatibility. This uses the same approach as the mmbi.epi package of the UMCG.
post_data( object, url, authorization_header = NULL, compress = TRUE, encrypt = TRUE, key = read_secret("tools.encryption_password") ) create_json_body( object, compress = TRUE, encrypt = TRUE, key = read_secret("tools.encryption_password") )post_data( object, url, authorization_header = NULL, compress = TRUE, encrypt = TRUE, key = read_secret("tools.encryption_password") ) create_json_body( object, compress = TRUE, encrypt = TRUE, key = read_secret("tools.encryption_password") )
object |
Any object of any size, preferably a data set |
url |
A character string specifying the target URL for the HTTP POST request. Must include the full scheme (e.g., |
authorization_header |
A character string specifying the value of the |
compress |
Should the object be compressed/decompressed? At least allowed: |
encrypt |
Should the object be encrypted/decrypted? This applies AES-GCM via |
key |
A character to be used as the encryption key. Internally, this is converted using |
## Not run: post_data(iris, url = "https://some-server:8000/post", compress = TRUE, encrypt = TRUE) ## End(Not run) # MANUAL WAY ----------------------------------------------------------- # use create_json_body() to make a(n encrypted) JSON of an object iris_json <- iris |> create_json_body(compress = TRUE, encrypt = TRUE) # curl -X POST https://some-server:8000/post # -H "Content-Type: application/json" # -d '...' # replace the "..." with the outcome of create_json_body(): iris_json## Not run: post_data(iris, url = "https://some-server:8000/post", compress = TRUE, encrypt = TRUE) ## End(Not run) # MANUAL WAY ----------------------------------------------------------- # use create_json_body() to make a(n encrypted) JSON of an object iris_json <- iris |> create_json_body(compress = TRUE, encrypt = TRUE) # curl -X POST https://some-server:8000/post # -H "Content-Type: application/json" # -d '...' # replace the "..." with the outcome of create_json_body(): iris_json
Checks if files contain privacy sensitive data and moves them to a 'vault folder' if this is the case.
privacy_check( path = getwd(), vault = paste0(path, "/vault"), log_file = paste0(vault, "/_privacy_log.txt"), suspicious_cols = "(zip.*code|postcode|bsn|geboortedatum)" )privacy_check( path = getwd(), vault = paste0(path, "/vault"), log_file = paste0(vault, "/_privacy_log.txt"), suspicious_cols = "(zip.*code|postcode|bsn|geboortedatum)" )
path |
path to check |
vault |
path to vault |
log_file |
path to log file where details will be written to |
suspicious_cols |
regular expression to match suspicious column names |
This function reads from a local or remote YAML file, as set in the environmental variable "secrets_file".
read_secret(property, file = Sys.getenv("secrets_file"))read_secret(property, file = Sys.getenv("secrets_file"))
property |
the property to read, case-sensitive |
file |
Either a character string naming a file or a connection open for reading. |
In the secrets file, the property name and value have to be separated with a colon (:), as is intended in YAML files.
The default value for file is the environmental variable "secrets_file".
The file will be read using read_yaml(), which allows almost any local path or remote connection (such as websites).
# for this example, create a temporary 'secrets' file my_secrets_file <- tempfile(fileext = ".yaml") Sys.setenv(secrets_file = my_secrets_file) writeLines(c("tenant_id: 8fb3c03060e02e89", "default_users: user_1"), my_secrets_file) read_secret("tenant_id") read_secret("default_users")# for this example, create a temporary 'secrets' file my_secrets_file <- tempfile(fileext = ".yaml") Sys.setenv(secrets_file = my_secrets_file) writeLines(c("tenant_id: 8fb3c03060e02e89", "default_users: user_1"), my_secrets_file) read_secret("tenant_id") read_secret("default_users")
Returns the relative reference directory for non-projects.
ref_dir(sub = "")ref_dir(sub = "")
sub |
relative subfolder or file |
This function returns the absolute path using tools::file_path_as_absolute().
Can be used in dplyr-syntax to remember values and objects for later use. Objects are (temporarily) stored in the certetoolbox package environment.
remember(.data, ...) recall(x = NULL, delete = TRUE)remember(.data, ...) recall(x = NULL, delete = TRUE)
.data |
|
... |
value(s) to be remembered |
x |
value to be recalled |
delete |
a logical to indicate whether the delete value after recalling |
values can be saved with remember() and recalled (and deleted) with recall().
library(dplyr, warn.conflicts = FALSE) x <- mtcars %>% remember(nrow(.)) recall() recall() # value removed x <- mtcars %>% remember(n = nrow(.)) recall(n) recall(n) # value removed ## Not run: tbl %>% filter(...) %>% remember(rows = nrow(.)) %>% group_by(...) %>% summarise(...) %>% plot2(title = "Test", subtitle = paste("n =", recall(rows))) ## End(Not run)library(dplyr, warn.conflicts = FALSE) x <- mtcars %>% remember(nrow(.)) recall() recall() # value removed x <- mtcars %>% remember(n = nrow(.)) recall(n) recall(n) # value removed ## Not run: tbl %>% filter(...) %>% remember(rows = nrow(.)) %>% group_by(...) %>% summarise(...) %>% plot2(title = "Test", subtitle = paste("n =", recall(rows))) ## End(Not run)
Formats bytes into human-readable units, from "kB" (10^3) to "YB" (10^23).
size_humanreadable(bytes, decimals = 1, decimal.mark = dec_mark())size_humanreadable(bytes, decimals = 1, decimal.mark = dec_mark())
bytes |
number of bytes |
decimals |
precision, not used for bytes and kilobytes |
decimal.mark |
decimal mark to use, defaults to |
If using object.size() on an object, this function is equal to using format2() to format the object size.
size_humanreadable(c(12, 1234, 123456, 12345678)) size_humanreadable(1024 ^ c(0:4))size_humanreadable(c(12, 1234, 123456, 12345678)) size_humanreadable(1024 ^ c(0:4))
Format a data.frame as flextable::flextable() with Certe style, bold headers and Dutch number formats. This function can also transform existing flextable and gtsummary objects to allow the formatting provided in this tbl_flextable() function.
tbl_flextable( x, row.names = rownames(x), row.names.bold = TRUE, rows.italic = NULL, rows.bold = NULL, rows.height = NULL, rows.fill = NULL, rows.zebra = TRUE, row.total = FALSE, row.total.name = "Totaal", row.total.function = sum, row.total.widths = NULL, row.total.bold = TRUE, row.extra.header = list(values = NULL, widths = 1), row.extra.footer = list(values = NULL, widths = 1), column.names = colnames(x), column.names.bold = TRUE, columns.width = NULL, columns.percent = NULL, columns.italic = NULL, columns.bold = NULL, columns.fill = NULL, columns.zebra = FALSE, column.total = FALSE, column.total.name = "Totaal", column.total.function = sum, column.total.bold = TRUE, align = "c", align.part = "all", caption = "", na = "", logicals = c("X", ""), round.numbers = 2, round.percent = 1, format.dates = "d mmm yyyy", decimal.mark = dec_mark(), big.mark = big_mark(), font.family = "Source Sans Pro", font.size = 9, font.size.header = font.size + 1, values.colour = NULL, values.fill = NULL, values.bold = NULL, values.italic = NULL, autofit = is.null(columns.width) & is.null(rows.height), autofit.fullpage = TRUE, autofit.fullpage.width = 16, vline = NULL, vline.part = c("body", "footer"), theme = current_markdown_colour(), colours = list(rows.fill.even = paste0(theme, "6"), rows.fill.odd = paste0(theme, "5"), columns.fill = paste0(theme, "5"), values.fill = paste0(theme, "3"), values.colour = theme, vline.colour = theme, hline.colour = theme, header.fill = theme, header.colour = "white", vline.header.colour = "white"), split.across.pages = NROW(x) > 37, print = !interactive(), ... ) ## S3 method for class 'certetoolbox_flextable' print(x, use_knitr = !is_latex_output(), ...)tbl_flextable( x, row.names = rownames(x), row.names.bold = TRUE, rows.italic = NULL, rows.bold = NULL, rows.height = NULL, rows.fill = NULL, rows.zebra = TRUE, row.total = FALSE, row.total.name = "Totaal", row.total.function = sum, row.total.widths = NULL, row.total.bold = TRUE, row.extra.header = list(values = NULL, widths = 1), row.extra.footer = list(values = NULL, widths = 1), column.names = colnames(x), column.names.bold = TRUE, columns.width = NULL, columns.percent = NULL, columns.italic = NULL, columns.bold = NULL, columns.fill = NULL, columns.zebra = FALSE, column.total = FALSE, column.total.name = "Totaal", column.total.function = sum, column.total.bold = TRUE, align = "c", align.part = "all", caption = "", na = "", logicals = c("X", ""), round.numbers = 2, round.percent = 1, format.dates = "d mmm yyyy", decimal.mark = dec_mark(), big.mark = big_mark(), font.family = "Source Sans Pro", font.size = 9, font.size.header = font.size + 1, values.colour = NULL, values.fill = NULL, values.bold = NULL, values.italic = NULL, autofit = is.null(columns.width) & is.null(rows.height), autofit.fullpage = TRUE, autofit.fullpage.width = 16, vline = NULL, vline.part = c("body", "footer"), theme = current_markdown_colour(), colours = list(rows.fill.even = paste0(theme, "6"), rows.fill.odd = paste0(theme, "5"), columns.fill = paste0(theme, "5"), values.fill = paste0(theme, "3"), values.colour = theme, vline.colour = theme, hline.colour = theme, header.fill = theme, header.colour = "white", vline.header.colour = "white"), split.across.pages = NROW(x) > 37, print = !interactive(), ... ) ## S3 method for class 'certetoolbox_flextable' print(x, use_knitr = !is_latex_output(), ...)
x |
a data.frame or a |
row.names |
row names to be displayed. Will be |
row.names.bold |
display row names in bold |
rows.italic |
column indexes of rows in italics |
rows.bold |
column indexes of rows in bold |
rows.height |
height of the rows in centimetres |
rows.fill |
the column indices of rows to be shaded |
rows.zebra |
banded rows in the body - equivalent to |
row.total |
add a row total (at the bottom of the table) |
row.total.name |
name of the row total |
row.total.function |
function used to calculate all numeric values per column (non-numeric columns are skipped) |
row.total.widths |
cell width in row total |
row.total.bold |
bold formatting of row total |
row.extra.header |
an extra header to be displayed above the table |
row.extra.footer |
an extra footer to show below the table |
column.names |
column names to be displayed. Can also be a named vector where the names are existing columns, or indices of columns. When this vector is smaller than |
column.names.bold |
display column names in bold |
columns.width |
width of columns. For |
columns.percent |
display the column indices as percentages using |
columns.italic |
column indices of columns to be displayed in italics |
columns.bold |
column indices of columns in bold |
columns.fill |
the column indices of rows to be shaded |
columns.zebra |
banded columns - equivalent to |
column.total |
adding a column total (to the right of the table) |
column.total.name |
name of the column total |
column.total.function |
function used to calculate all numeric values per row |
column.total.bold |
bold formatting of column total |
align |
default is "c", which aligns everything centrally. Use "r", "l", "c" and "j"/"u" (justify/align) to change alignment. Can be a vector or a character (like "lrrrcc") |
align.part |
part of the table where the alignment should take place ("all", "header", "body", "footer") |
caption |
table caption |
na |
text for missing values |
logicals |
vector with two values that replace |
round.numbers |
number of decimal places to round up for numbers |
round.percent |
number of decimal places to round to when using |
format.dates |
see |
decimal.mark |
decimal separator, defaults to |
big.mark |
thousands separator, defaults to |
font.family |
table font family |
font.size |
table font size |
font.size.header |
font size of header |
values.colour, values.fill, values.bold, values.italic
|
values to be formatted |
autofit |
format table in width automatically. This will apply |
autofit.fullpage |
display table across width of page |
autofit.fullpage.width |
set number of centimetres to width of table |
vline |
indices of columns to have a vertical line to their right |
vline.part |
part of the table where the vertical lines should be placed ("all", "header", "body", "footer") |
theme |
a Certe colour theme, defaults to |
colours |
a list with the following named character values: |
split.across.pages |
a logical whether tables are allowed to split across page. This argument only has effect for PDF output. |
print |
forced printing (required in a |
... |
not used |
use_knitr |
use the |
Run tbl_markdown() on a flextable object to transform it into markdown for use in Quarto or R Markdown reports. If print = TRUE in non-interactive sessions (Quarto or R Markdown), the flextable object will also be printed in markdown.
The value for theme is dependent on whether a colour is set in the markdown YAML header. Otherwise, use theme to set a Certe colour theme, defaults to "certeblauw":
# from the example below tbl_flextable(df)
tbl_flextable(df, theme = "certeroze")
tbl_flextable(df, theme = "certegeel")
tbl_flextable(df, theme = "certegroen", vline = c(2:3))
tbl_flextable( df, theme = "certelila", row.total = TRUE, row.total.function = median, round.numbers = 4, row.extra.header = list(values = LETTERS[1:5]) )
flextable::flextable object
## Not run: # generate a data.frame df <- data.frame(text = LETTERS[1:10], `decimal numbers` = runif(10, 0, 10), `whole numbers` = as.integer(runif(10, 0, 10)), `logical values` = as.logical(round(runif(10, 0, 1))), dates = today() - runif(10, 200, 2000), stringsAsFactors = FALSE) # default tbl_flextable(df) # dataset has no row names tbl_flextable(mtcars) # dataset has row names # print in markdown df |> tbl_flextable() |> tbl_markdown() # transform a gtsummary to a flextable iris |> tbl_gtsummary(Species, add_p = TRUE) |> tbl_flextable() # extra formatting tbl_flextable(df, logicals = c("X", "-"), # replaces TRUE en FALSE values.colour = "X", values.fill = "X", row.names = "S. aureus", columns.italic = 1, format.dates = "ddd dd-mm-yy", round.numbers = 3) # row totals tbl_flextable(df, row.total = TRUE, # add row total row.total.function = max, # instead of sum() row.total.name = "Maximum", # also works with dates columns.percent = 2, # 2nd column as percentages round.percent = 0) # rounding percentages # column names tbl_flextable(df, column.names = c("1" = "Column 1", "2" = "Column 2", dates = "DATES!")) tbl_flextable(df, column.names = LETTERS) # vertical lines, alignment and row names tbl_flextable(df, align = "lrrcc", # also works: c("l", "r", "r", "c", "c") font.size = 12, vline = c(2, 4), vline.part = "all", row.names = paste("Experiment", 1:10)) # width of cells and table tbl_flextable(data.frame(test1 = "A", test2 = "B"), vline = 1, autofit.fullpage.width = 16, # default values in cm columns.width = c(1, 3)) # ratio; cells become 4 and 12 cm tbl_flextable(data.frame(test1 = "A", test2 = "B"), vline = 1, autofit.fullpage = FALSE, # no fullpage autofit columns.width = c(1, 3)) # cells become 1 and 3 cm # adding extra header or footer tbl_flextable(data.frame(test1 = "A", test2 = "B"), row.extra.header = list(values = c("Header", "Header"), widths = c(1, 1)), row.extra.footer = list(values = c("Footer", "Footer"), widths = c(1, 1))) ## End(Not run)## Not run: # generate a data.frame df <- data.frame(text = LETTERS[1:10], `decimal numbers` = runif(10, 0, 10), `whole numbers` = as.integer(runif(10, 0, 10)), `logical values` = as.logical(round(runif(10, 0, 1))), dates = today() - runif(10, 200, 2000), stringsAsFactors = FALSE) # default tbl_flextable(df) # dataset has no row names tbl_flextable(mtcars) # dataset has row names # print in markdown df |> tbl_flextable() |> tbl_markdown() # transform a gtsummary to a flextable iris |> tbl_gtsummary(Species, add_p = TRUE) |> tbl_flextable() # extra formatting tbl_flextable(df, logicals = c("X", "-"), # replaces TRUE en FALSE values.colour = "X", values.fill = "X", row.names = "S. aureus", columns.italic = 1, format.dates = "ddd dd-mm-yy", round.numbers = 3) # row totals tbl_flextable(df, row.total = TRUE, # add row total row.total.function = max, # instead of sum() row.total.name = "Maximum", # also works with dates columns.percent = 2, # 2nd column as percentages round.percent = 0) # rounding percentages # column names tbl_flextable(df, column.names = c("1" = "Column 1", "2" = "Column 2", dates = "DATES!")) tbl_flextable(df, column.names = LETTERS) # vertical lines, alignment and row names tbl_flextable(df, align = "lrrcc", # also works: c("l", "r", "r", "c", "c") font.size = 12, vline = c(2, 4), vline.part = "all", row.names = paste("Experiment", 1:10)) # width of cells and table tbl_flextable(data.frame(test1 = "A", test2 = "B"), vline = 1, autofit.fullpage.width = 16, # default values in cm columns.width = c(1, 3)) # ratio; cells become 4 and 12 cm tbl_flextable(data.frame(test1 = "A", test2 = "B"), vline = 1, autofit.fullpage = FALSE, # no fullpage autofit columns.width = c(1, 3)) # cells become 1 and 3 cm # adding extra header or footer tbl_flextable(data.frame(test1 = "A", test2 = "B"), row.extra.header = list(values = c("Header", "Header"), widths = c(1, 1)), row.extra.footer = list(values = c("Footer", "Footer"), widths = c(1, 1))) ## End(Not run)
gtsummary
Summarise a data.frame as gtsummary with Dutch defaults. These objects are based on the gt package by RStudio. To provide Certe style and compatibility with MS Word, use tbl_flextable() to transform the gtsummary object.
tbl_gtsummary( x, by = NULL, label = NULL, digits = 1, ..., language = "nl", column1_name = "Eigenschap", add_n = FALSE, add_p = FALSE, add_ci = FALSE, add_overall = FALSE, decimal.mark = dec_mark(), big.mark = big_mark() )tbl_gtsummary( x, by = NULL, label = NULL, digits = 1, ..., language = "nl", column1_name = "Eigenschap", add_n = FALSE, add_p = FALSE, add_ci = FALSE, add_overall = FALSE, decimal.mark = dec_mark(), big.mark = big_mark() )
x |
|
by |
( |
label |
( |
digits |
( |
... |
Arguments passed on to |
language |
the language to use, defaults to Dutch |
column1_name |
name to use for the first column |
add_n |
add the overall N using |
add_p |
add the p values |
add_ci |
add the confidence interval using |
add_overall |
add the overall statistics using |
decimal.mark |
decimal separator, defaults to |
big.mark |
thousands separator, defaults to |
tbl_gtsummary() creates a summary table with gtsummary::tbl_summary(), to which different extra columns can be added e.g. with add_p = TRUE and add_overall = TRUE.
# These examples default to the Dutch language iris |> tbl_gtsummary() iris |> tbl_gtsummary(Species, add_p = TRUE) iris |> tbl_gtsummary(Species, add_n = TRUE) # support strata by providing iris2 <- iris iris2$Category <- sample(LETTERS[1:2], size = 150, replace = TRUE) head(iris2) iris2 |> tbl_gtsummary(c(Category, Species)) # transform to flextable # (formats to Certe style and allows rendering to Word) iris |> tbl_gtsummary(Species) |> tbl_flextable()# These examples default to the Dutch language iris |> tbl_gtsummary() iris |> tbl_gtsummary(Species, add_p = TRUE) iris |> tbl_gtsummary(Species, add_n = TRUE) # support strata by providing iris2 <- iris iris2$Category <- sample(LETTERS[1:2], size = 150, replace = TRUE) head(iris2) iris2 |> tbl_gtsummary(c(Category, Species)) # transform to flextable # (formats to Certe style and allows rendering to Word) iris |> tbl_gtsummary(Species) |> tbl_flextable()
Prints a data.frame as Markdown, LaTeX or HTML using knitr::kable(), with bold headers and Dutch number formats.
tbl_markdown( x, row.names = rownames(x), column.names = colnames(x), align = NULL, padding = 2, caption = "", na = "", type = "markdown", format.dates = "dd-mm-yyyy", decimal.mark = dec_mark(), big.mark = big_mark(), logicals = c("X", ""), columns.percent = NA, column.names.bold = TRUE, round.numbers = 2, round.percent = 1, newlines.leading = 0, newlines.trailing = 2, print = TRUE )tbl_markdown( x, row.names = rownames(x), column.names = colnames(x), align = NULL, padding = 2, caption = "", na = "", type = "markdown", format.dates = "dd-mm-yyyy", decimal.mark = dec_mark(), big.mark = big_mark(), logicals = c("X", ""), columns.percent = NA, column.names.bold = TRUE, round.numbers = 2, round.percent = 1, newlines.leading = 0, newlines.trailing = 2, print = TRUE )
x |
a data.frame or a |
row.names |
row names to be displayed |
column.names |
column names to be displayed |
align |
alignment of columns (default: numbers to the right, others to the left) |
padding |
extra cell padding |
caption |
caption of table |
na |
text for missing values (default: |
type |
type of formatting the table - valid options are |
format.dates |
formatting of dates, will be evaluated with |
decimal.mark |
decimal separator, defaults to |
big.mark |
thousands separator, defaults to |
logicals |
vector with two values that replace |
columns.percent |
display the column indices as percentages using |
column.names.bold |
display column names in bold |
round.numbers |
number of decimal places to round up for numbers |
round.percent |
number of decimal places to round to when using |
newlines.leading |
number of white lines to print before the table |
newlines.trailing |
number of white lines to print after the table |
print |
only useful when input is a Flextable: force printing |
When in an R Markdown rapport a table is printed using this function, column headers only print well if newlines.leading >= 2, or by manually using cat("\\n\\n") before printing the table.
character
tbl_markdown(mtcars[1:6, 1:6], padding = 1)tbl_markdown(mtcars[1:6, 1:6], padding = 1)
Update a data.frame using specific integers for row numbers or a vectorised filter. Also supports dplyr groups. see Examples.
## S3 method for class 'data.frame' update(object, rows, ...)## S3 method for class 'data.frame' update(object, rows, ...)
object |
|
rows |
row numbers or a logical vector |
... |
arguments passed on to |
iris |> update(3:4, Species = c("A", "B")) |> head() iris |> update(Species == "setosa" & Sepal.Length > 5, Species = "something else") |> head() if (require("dplyr")) { # also supports dplyr groups: iris |> group_by(Species) |> # update every 2nd to 4th row in group update(2:4, Species = "test") |> # groups will be updated automatically count() }iris |> update(3:4, Species = c("A", "B")) |> head() iris |> update(Species == "setosa" & Sepal.Length > 5, Species = "something else") |> head() if (require("dplyr")) { # also supports dplyr groups: iris |> group_by(Species) |> # update every 2nd to 4th row in group update(2:4, Species = "test") |> # groups will be updated automatically count() }
Download Wikipedia daily page views for any language, using the Wikimedia REST API.
wikipedia_pageviews( articles, date_range = last_6_months(), language = "nl", platform = c("all-access", "mobile-web", "mobile-app", "desktop"), agent = c("all-agents", "user", "spider", "automated") )wikipedia_pageviews( articles, date_range = last_6_months(), language = "nl", platform = c("all-access", "mobile-web", "mobile-app", "desktop"), agent = c("all-agents", "user", "spider", "automated") )
articles |
Wikipedia article title(s) |
date_range |
defaults to |
language |
defaults to |
platform |
defaults to |
agent |
defaults to |
wikipedia_pageviews("Griep") articles <- c("Griep", "Koorts", "Hoest", "Verkoudheid", "Influenzavirus A", "Respiratoir syncytieel virus", "Keelpijn", "SARS-CoV-2") if (require("certeplot2") && require("certestats") && require("dplyr")) { articles |> wikipedia_pageviews(c("2024-07-01", "2025-02-01")) |> group_by(article) |> mutate(z = z_score(views), z_ma = moving_average(z, w = 7, side = "left")) |> plot2( x = date, y = z_ma, category = article, type = "line", category.sort = "freq-asc", legend.position = "right", y.title = "7-daagse Z-score", x.title = "", title = "Wikipedia bezochte pagina's", subtitle = "Z-scores respiratoire seizoen") } if (require("certeplot2")) { wikipedia_pageviews("Dog", language = "en", date_range = last_5_years()) |> plot2(x = date, y = views) }wikipedia_pageviews("Griep") articles <- c("Griep", "Koorts", "Hoest", "Verkoudheid", "Influenzavirus A", "Respiratoir syncytieel virus", "Keelpijn", "SARS-CoV-2") if (require("certeplot2") && require("certestats") && require("dplyr")) { articles |> wikipedia_pageviews(c("2024-07-01", "2025-02-01")) |> group_by(article) |> mutate(z = z_score(views), z_ma = moving_average(z, w = 7, side = "left")) |> plot2( x = date, y = z_ma, category = article, type = "line", category.sort = "freq-asc", legend.position = "right", y.title = "7-daagse Z-score", x.title = "", title = "Wikipedia bezochte pagina's", subtitle = "Z-scores respiratoire seizoen") } if (require("certeplot2")) { wikipedia_pageviews("Dog", language = "en", date_range = last_5_years()) |> plot2(x = date, y = views) }