Title: | A Utility Package to Help you Deal with "Pignas" |
---|---|
Description: | Pigna [_pìn'n'a_] is the Italian word for pine cone. In jargon, it is used to identify a task which is boring, banal, annoying, painful, frustrating and maybe even with a not so beautiful or rewarding result, just like the obstinate act of trying to challenge yourself in extracting pine nuts from a pine cone, provided that, in the end, you will find at least one inside it. Here you can find a backpack of functions to be used to solve small everyday problems of coding or analyzing (clinical) data, which would be normally solved using quick-and-dirty patches. You will be able to convert 'Hmisc' and 'rms' summary()es into data.frames ready to be rendered by 'pander' and 'knitr'. You can access easy-to-use wrappers to activate essential but useful progress bars (from 'progress') into your loops or functionals. Easy setup and control Telegram's bots (from 'telegram.bot') to send messages or to divert error messages to a Telegram's chat. You also have some utilities helping you in the development of packages, like the activation of the same user interface of 'usethis' into your package, or call polite functions to ask a user to install other packages. Finally, you find a set of thematic sets of packages you may use to set up new environments quickly, installing them in a single call. |
Authors: | Corrado Lanera [aut, cre, cph] |
Maintainer: | Corrado Lanera <[email protected]> |
License: | GPL-3 |
Version: | 0.9.1 |
Built: | 2024-11-15 03:36:50 UTC |
Source: | https://github.com/corradolanera/depigner |
Adjust P-values of a tidy_summary
object
adjust_p(x, method) ## S3 method for class 'tidy_summary' adjust_p(x, method = "BH")
adjust_p(x, method) ## S3 method for class 'tidy_summary' adjust_p(x, method = "BH")
x |
a |
method |
(chr, default = "BH") a valid method for
|
a tidy_summary
object with the Ps adjusted
library(Hmisc) my_summary <- summary(Species ~ ., data = iris, method = "reverse", test = TRUE ) tidy_summary(my_summary, prtest = "P") %>% adjust_p()
library(Hmisc) my_summary <- summary(Species ~ ., data = iris, method = "reverse", test = TRUE ) tidy_summary(my_summary, prtest = "P") %>% adjust_p()
This data are imported from the package vcd, which depends on a package (i.e., mvtnorm) which require R >= 3.5. For this reason we do not import the package vcd, but only this dataset. Which is used only in the examples and tests.
Arthritis
Arthritis
A data.frame with 84 obs. and 5 var.
check_for_bot_options
check if a telegram bot and
corresponding chat, exist.
check_for_bot_options(chat_id, bot)
check_for_bot_options(chat_id, bot)
chat_id |
a chat id |
bot |
a bot |
invisible lgl indicating if check pass (TRUE) or not (FALSE)
ci2p
compute the p-value related with a provided confidence
interval. It considers a symmetric distribution (by default standard
normal).
ci2p( est, lower, upper, log_transform = FALSE, conf = 0.95, qdist = stats::qnorm, pdist = stats::pnorm )
ci2p( est, lower, upper, log_transform = FALSE, conf = 0.95, qdist = stats::qnorm, pdist = stats::pnorm )
est |
estimated value |
lower |
lower bound of the confidence level |
upper |
upper bound of the confidence level |
log_transform |
(default 'FALSE') flag indicating if a log transformation as to apply to the data |
conf |
(default '95%') confidence level |
qdist |
(default 'qnorm') quantile function |
pdist |
(default 'pnorm') distribution function |
Confidence level can be customize (by default 95 possible to apply a log transformation in case of proportions.
a p-value
ci2p(1.125, 0.634, 1.999, log_transform = TRUE) ci2p(1.257, 1.126, 1.403, log_transform = TRUE)
ci2p(1.125, 0.634, 1.999, log_transform = TRUE) ci2p(1.257, 1.126, 1.403, log_transform = TRUE)
Divert output errors to the telegram bot
errors_to_telegram( chat_name = Sys.getenv("R_telegram_error_chat_name"), bot_name = getOption("depigner.bot_name") )
errors_to_telegram( chat_name = Sys.getenv("R_telegram_error_chat_name"), bot_name = getOption("depigner.bot_name") )
chat_name |
a |
bot_name |
a |
a
if (interactive()) { library(depigner) errors_to_telegram() }
if (interactive()) { library(depigner) errors_to_telegram() }
A wrapper to relax
gdp(time = 4L, freq = 0.05)
gdp(time = 4L, freq = 0.05)
time |
[num] number of seconds needed to relax yourself (default = 4) |
freq |
[num] rotating frequency (default = 0.05/s) |
invisible()
if (interactive()) { gdp() gdp(5) required_seconds_of_relax <- 10 # AKA: "conta fino a dieci!" rate_of_anxiety <- 1/1000 # AKA: "mi girano a mille!" gdp(required_seconds_of_relax, rate_of_anxiety) }
if (interactive()) { gdp() gdp(5) required_seconds_of_relax <- 10 # AKA: "conta fino a dieci!" rate_of_anxiety <- 1/1000 # AKA: "mi girano a mille!" gdp(required_seconds_of_relax, rate_of_anxiety) }
These functions decide and report if a single variable represented by a single instance of an ‘Hmisc'’s [describe][Hmisc::describe] object will considered a categorical variable or a continuous one.
htype(x, n_unique = 10L) htypes(x, n_unique = 10L) ## S3 method for class 'describe' htypes(x, n_unique = 10L) ## Default S3 method: htypes(x, n_unique = 10L) is_hcat(x) is_hcon(x, n_unique = 10L)
htype(x, n_unique = 10L) htypes(x, n_unique = 10L) ## S3 method for class 'describe' htypes(x, n_unique = 10L) ## Default S3 method: htypes(x, n_unique = 10L) is_hcat(x) is_hcon(x, n_unique = 10L)
x |
an instance of the class [describe][Hmisc::describe], in the cases of "singular" functions (ie 'is_*()' or 'htype()') it must be a single-variable [describe][Hmisc::describe] object. |
n_unique |
(int, 10L) the minimum number of distinct values a numeric variable must have before plot.describe uses it in a continuous variable plot. |
A "single" object of ‘Hmisc'’s [describe][Hmisc::describe] class represents a variable. When you plot and object of class [describe][Hmisc::describe] the plot function decide if it is a continuous variable or a categorical one to plot it in the correspond plot. It is also possible that the variable is not considered in none of that categories, in which case it will not be plotted at all.
These functions have been produced/deduced from reading the source code of ‘Hmisc'’s [plot][Hmisc::describe]. In particular, from the definition of the (two distinct) functions 'f' defined within it (one for categorical variables and the other for continuous variables). Both lead to a possible execution of 'warning("no categorical variable found")' or 'warning("no continuous variable found")'. I tried to keep the same names/code/logic that I found there.
(chr) 'htype' returns one of "cat" (if 'x' will be considered categorical), "con" (if 'x' will be considered continuous), "none" (if 'x' will be not considered categorical nor continuous, and hence it will be not plotted), or "both" (with a warning, if the variable will be considered both categorical and continuous. This would possibly never happen).
(chr) character vector of the types identified by [htype] for every variable represented in (each element of) 'x'.
(lgl) 'is_hcat' returns TRUE if x will be considered categorical.
(lgl) 'is_hcon' returns TRUE if x will be considered continuous.
htypes()
: Report types for multi-variables objects
is_hcat()
: Check if a single-instance of a
[describe][Hmisc::describe] object is categorical.
is_hcon()
: Check if a single-instance of a
[describe][Hmisc::describe] object is continuous.
[describe][Hmisc::describe],
[is_hdesc], [is_single_hdesc]
Gist with test and usage examples: https://bit.ly/htype-gist
library(Hmisc) desc <- describe(mtcars) htype(desc[["vs"]]) # "cat" htype(desc[["mpg"]]) # "con" htype(desc[["cyl"]]) # "none" htypes(desc) # c( # mpg = "con", cyl = "none", disp = "con", # hp = "con", drat = "con", wt = "con", qsec = "con", # vs = "cat", am = "cat", gear = "none", # carb = "none" # ) htypes(mtcars) # htypes(desc) htypes(letters) # "none" is_hcat(desc[["vs"]]) # TRUE is_hcat(desc[["mpg"]]) # FALSE is_hcon(desc[["vs"]]) # FALSE is_hcon(desc[["mpg"]]) # TRUE
library(Hmisc) desc <- describe(mtcars) htype(desc[["vs"]]) # "cat" htype(desc[["mpg"]]) # "con" htype(desc[["cyl"]]) # "none" htypes(desc) # c( # mpg = "con", cyl = "none", disp = "con", # hp = "con", drat = "con", wt = "con", qsec = "con", # vs = "cat", am = "cat", gear = "none", # carb = "none" # ) htypes(mtcars) # htypes(desc) htypes(letters) # "none" is_hcat(desc[["vs"]]) # TRUE is_hcat(desc[["mpg"]]) # FALSE is_hcon(desc[["vs"]]) # FALSE is_hcon(desc[["mpg"]]) # TRUE
Packages imported by a package
imported_from(x, include_self = FALSE)
imported_from(x, include_self = FALSE)
x |
(chr) the package you would like to see its imports |
include_self |
(lgl, FALSE) do you like to include 'x' itself in the output? |
(chr) vector of packages imported by 'x'
imported_from("depigner")
imported_from("depigner")
This function is used to politely ask the user to install requiring packages. It is intended to be used in interactive sessions only.
install_pkg_set(set = pkg_all, dependencies = TRUE)
install_pkg_set(set = pkg_all, dependencies = TRUE)
set |
(chr) packages' names |
dependencies |
do you want to install the dependencies? |
You can pass arbitrarily sets of packages; on the other hands, you can use some sets already prepared and included into 'depigner' (see '?pkg_sets').
invisible character vector of the subset of 'interested' which was not already present, and installed.
By default this function install all the packages listed in 'pkg_all', which is the union of all the sets of packages listed in '?pkg_sets'.
please_install, pkg_sets
## Not run: install_pkg_set() # to install all the `?pkg_all` ## End(Not run)
## Not run: install_pkg_set() # to install all the `?pkg_all` ## End(Not run)
These two function are useful to test if an object is of class [Hmisc][Hmisc::describe].
is_hdesc(x) is_single_hdesc(x)
is_hdesc(x) is_single_hdesc(x)
x |
an object to test if it is of class 'describe'. |
In 'Hmisc' both "single" 'describe' objects and lists of them are of class 'describe'. In particular, even if 'Hmisc::describe()' results in a single variable description, it is directly the "single" 'describe' object and not a list of them with only a single 'describe' object included!
'is_hdesc()' test for general inheritance.
'is_single_hdesc()' test for single instance of a 'describe' object.
(lgl) is 'x' (a single element or a general) 'describe' object?
[describe][Hmisc::describe]
[is_hcat], [is_hcon], [htype], [htypes]
library(Hmisc) desc <- describe(mtcars) is_hdesc(desc) # TRUE is_hdesc(desc[[1L]]) # TRUE is_single_hdesc(desc) # FALSE is_single_hdesc(desc[[1L]]) # TRUE
library(Hmisc) desc <- describe(mtcars) is_hdesc(desc) # TRUE is_hdesc(desc[[1L]]) # TRUE is_single_hdesc(desc) # FALSE is_single_hdesc(desc[[1L]]) # TRUE
Statistical tests for paired categorical variable.
paired_test_categorical(tab)
paired_test_categorical(tab)
tab |
a frequency table (an integer 'table', if a 'matrix' is provided, it will be coerced to a 'table' internally) |
If the test is requested for two paired groups, the
mcnemar.test
is used.
If the test is requested for more than two paired groups, the test
based on Cochran-Mantel-Haenzen for repeated measures is used
(powered by mantelhaen.test
)
A list with components 'P' (the computed P-value), 'stat' (the test statistic, either t or F), 'df' (degrees of freedom), 'testname' (test name), 'statname' (statistic name), 'namefun' ("paired_tstat", "rep_aov"), 'latexstat' (LaTeX representation of statname), 'plotmathstat' (for R - the plotmath representation of 'statname', as a character string), 'note' (contains a character string note about the test).
This function could be used as 'catTest' option in the
summary.formula
with method 'reverse'.
library(Hmisc) data(Arthritis) ## two groups summary(Treatment ~ Sex, data = Arthritis, method = "reverse", test = TRUE, catTest = paired_test_categorical ) ## more than two groups summary(Improved ~ Sex, data = Arthritis, method = "reverse", test = TRUE, catTest = paired_test_categorical )
library(Hmisc) data(Arthritis) ## two groups summary(Treatment ~ Sex, data = Arthritis, method = "reverse", test = TRUE, catTest = paired_test_categorical ) ## more than two groups summary(Improved ~ Sex, data = Arthritis, method = "reverse", test = TRUE, catTest = paired_test_categorical )
Statistical tests for paired continuous variable.
paired_test_continuous(group, x)
paired_test_continuous(group, x)
group |
(fct) vector of groups |
x |
(num) vector of observations. Note: length of 'x' is considered equal to the number of subjects by the number of groups. Observation must be provided by subject (e.g. c(a1, b1, c1, a2, b2, c2, a3, b3, c3, a4, b4, c4), where the letters, a, b, c, and d represents the groups and the numbers represents the patients' ids). Note only patient with observation in all the levels considered will be used. |
If the test is requested for two paired groups, the
t.test
is used.
If the test is requested for more than two groups, the test based on
ANOVA for repeated measures is used (powered by
aov
)
A list with components 'P' (the computed P-value), 'stat' (the test statistic, either t or F), 'df' (degrees of freedom), 'testname' (test name), 'statname' (statistic name), 'namefun' ("paired_tstat", "rep_aov"), 'latexstat' (LaTeX representation of statname), 'plotmathstat' (for R - the plotmath representation of 'statname', as a character string), 'note' (contains a character string note about the test).
This function could be used as 'conTest' option in the
summary.formula
with method 'reverse'.
library(Hmisc) ## two groups summary(Species ~ ., data = iris[iris[["Species"]] != "setosa", ], method = "reverse", test = TRUE, conTest = paired_test_continuous ) ## more than two groups summary(Species ~ ., data = iris, method = "reverse", test = TRUE, conTest = paired_test_continuous ) ## without Hmisc two_obs <- iris[["Sepal.Length"]][iris[["Species"]] != "setosa"] two_groups <- iris[["Species"]][iris[["Species"]] != "setosa"] paired_test_continuous(two_groups, two_obs) obs <- iris[["Sepal.Length"]] many_groups <- iris[["Species"]] paired_test_continuous(many_groups, obs)
library(Hmisc) ## two groups summary(Species ~ ., data = iris[iris[["Species"]] != "setosa", ], method = "reverse", test = TRUE, conTest = paired_test_continuous ) ## more than two groups summary(Species ~ ., data = iris, method = "reverse", test = TRUE, conTest = paired_test_continuous ) ## without Hmisc two_obs <- iris[["Sepal.Length"]][iris[["Species"]] != "setosa"] two_groups <- iris[["Species"]][iris[["Species"]] != "setosa"] paired_test_continuous(two_groups, two_obs) obs <- iris[["Sepal.Length"]] many_groups <- iris[["Species"]] paired_test_continuous(many_groups, obs)
Simple wrapper for progress_bar
for standard
and quickly ready progress bars; including messages, bar progression,
percentage and time elapsed, and ETA.
pb_len(.x, width = 76L, show_after = 2L, clear = FALSE) tick(pb, what = "")
pb_len(.x, width = 76L, show_after = 2L, clear = FALSE) tick(pb, what = "")
.x |
(int) total number of step to count |
width |
(int, default = 76) total console width used by the bar |
show_after |
(num, default = 2) minimum number of seconds needed for the process to display the progress bar |
clear |
(lgl, default = FALSE) if TRUE, at the end of the process the progress bar will be cleared |
pb |
an object of class |
what |
(chr, default = "") short prompt to see at the beginning of the progressbar |
a progress_bar
object
tick()
: wrapper function to update the progress bar
pb <- pb_len(100) for (i in 1:100) { Sys.sleep(0.1) tick(pb, paste("i = ", i)) }
pb <- pb_len(100) for (i in 1:100) { Sys.sleep(0.1) tick(pb, paste("i = ", i)) }
These are presets of packages which can be used to easily prepare systems installing them in groups or all together (using 'pkg_all').
pkg_misc pkg_utils pkg_speed pkg_mlt pkg_stat pkg_stan pkg_devel pkg_docs pkg_prod pkg_all
pkg_misc pkg_utils pkg_speed pkg_mlt pkg_stat pkg_stan pkg_devel pkg_docs pkg_prod pkg_all
An object of class character
of length 3.
An object of class character
of length 7.
An object of class character
of length 4.
An object of class character
of length 6.
An object of class character
of length 9.
An object of class character
of length 2.
An object of class character
of length 13.
An object of class character
of length 5.
An object of class character
of length 4.
An object of class character
of length 51.
Packages imported by the mentioned packages are not included into the sets (that is the reason why, e.g., you do not see 'shiny' or 'knitr', ...).
pkg_misc
: Packages for side-interest purposes, including
'beepr', 'fortunes', and 'telegram.bot'.
pkg_utils
: Utilities for data analyses, including 'here',
'lobstr', 'progress', 'progressr', 'readxl', 'tidyverse',
and 'writexl'.
pkg_speed
: Are you in a hurry?! This includes 'furrr',
'parallel', 'snow', and 'tidyfast'.
pkg_mlt
: Machine Learning in R (we do not include
'keras' nor 'tensorflow' which require _ad hoc_ configuration).
This includes 'caret', 'glmnet', 'mlr3', 'snow',
'tidymodels', 'tidytext', and 'tm'.
pkg_stat
: (Clinical oriented) statistical analyses in R.
This includes 'CBPS', 'cobalt', 'dlnm', 'ggeffects',
'MatchIt', 'mice', 'rms', 'twang', and 'WeightIt'.
pkg_stan
: Stan analyses in R (Alert: these packages
require 'stan' be installed into the system. They are not included
into 'pkg_all'). This includes 'rstanarm', and 'brms'.
pkg_devel
: Develop stuff in R. This includes 'assertive',
'checkmate', 'covr', 'lintr', 'profvis', 'pryr',
'renv', 'roxygen2', 'styler', 'tarchetypes', 'testthat',
'spelling', and 'usethis'.
pkg_docs
: Write and render things in R. This includes
'blogdown', 'DT', 'pander', and 'pkgdown'.
pkg_prod
: for develop and put in production stuffs
('shiny' app included). This includes 'golem', 'docopt',
'plumbr', and 'shinyjs'.
pkg_all
: Union of the 'pkg_misc', 'pkg_utils', 'pkg_speed',
'pkg_mlt', 'pkg_stat', 'pkg_devel', 'pkg_docs', and 'pkg_prod'
pkg_* sets.
install_pkg_set
A polite helper for installing and update packages (quite exactly) inspired from a function used by Hadley Wickham at 'RStudio::conf 2018 - San Diego'.
please_install(pkgs, install_fun = install.packages, ...)
please_install(pkgs, install_fun = install.packages, ...)
pkgs |
character vector of package(s) to install |
install_fun |
function to use for installing package(s) |
... |
further options for install_fun |
invisible
This is a generic function to send some object to telegram.
send_to_telegram(x, ..., chat_id, bot) ## S3 method for class 'character' send_to_telegram( x, type = c("message", "photo", "document", "audio", "animation", "video", "voice", "sticker", "location", "videonote"), ..., chat_id = getOption("depigner.chat_id"), bot = getOption("depigner.bot") ) ## S3 method for class 'gg' send_to_telegram( x, fileext = c("png", "pdf", "jpeg", "tiff", "bmp"), ..., chat_id = getOption("depigner.chat_id"), bot = getOption("depigner.bot") )
send_to_telegram(x, ..., chat_id, bot) ## S3 method for class 'character' send_to_telegram( x, type = c("message", "photo", "document", "audio", "animation", "video", "voice", "sticker", "location", "videonote"), ..., chat_id = getOption("depigner.chat_id"), bot = getOption("depigner.bot") ) ## S3 method for class 'gg' send_to_telegram( x, fileext = c("png", "pdf", "jpeg", "tiff", "bmp"), ..., chat_id = getOption("depigner.chat_id"), bot = getOption("depigner.bot") )
x |
object to send (often a character string) |
... |
further argument to pass to the sending methods (see
|
chat_id |
chat_id in which send the object. By default all the
methods consider the chat_id defined in the previous run of
|
bot |
( |
type |
(chr, default = "message") the type of text represent
|
fileext |
(chr, default "png") one of the possible file format supported: "png", "pdf", "jpeg", "tiff" or "bmp" |
By default it use the bot and chat_id configured by
start_bot_for_chat
. The user can pass a custom bot or
chat_id providing them to the corresponding argument.
invisible the object x.
## Not run: library(depigner) library(ggplot2) start_bot_for_chat() send_to_telegram("hello world") gg <- ggplot(mtcars, aes(x = mpg, y = hp, colour = cyl)) + geom_point() send_to_telegram( "following an `mtcars` coloured plot", parse_mode = "Markdown" ) send_to_telegram(gg) ## End(Not run)
## Not run: library(depigner) library(ggplot2) start_bot_for_chat() send_to_telegram("hello world") gg <- ggplot(mtcars, aes(x = mpg, y = hp, colour = cyl)) + geom_point() send_to_telegram( "following an `mtcars` coloured plot", parse_mode = "Markdown" ) send_to_telegram(gg) ## End(Not run)
This function set up what is necessary to telegram.bot
package to be used in a more easy way by the function provided by
the depigner.
start_bot_for_chat( chat_name = Sys.getenv("R_telegram_default_chat_name"), bot_name = getOption("depigner.bot_name") )
start_bot_for_chat( chat_name = Sys.getenv("R_telegram_default_chat_name"), bot_name = getOption("depigner.bot_name") )
chat_name |
(chr, NA) The name of the chat you want to the bot send.is linked to. If NA (default) it uses the default chat of the bot. |
bot_name |
(chr, NULL) This argument should be left NULL. If NULL, the function bring the bot name from the environmental variable "R_telegram_bot_name". You can pass another bot's name here as a character string too (note that in this case in the .Renviron you must have an entry like 'R_TELEGRAM_BOT_<yourbotname>=......' containing the token related to the bot). |
Before you can use the depigner
facilities (or the
telegram.bot
ones) to use your bot to chat with
Telegram from R, you have to set the bot up.
To set up a bot in telegram, find @BotFather
on telegram. Send
the message \start
to it, and then send the message
\newbot
to it too. Next you have to follow the very simple
instruction it gives you. At the end of the process, save your bot
token and never share it publicly!!
After your bot is created, go to your bot default chat profile and
send the message \start
.
Now you can return to R and put both the bot's name and token into
the .Renviron file. To access to it you can use
edit_r_environ
which will open the
'.Renviron' file, ready to be modified.
You need to insert two lines, namely the one for your bot's name:
'R_telegram_bot_name=<name_of_my_bot>'
and one for its token:
'R_TELEGRAM_BOT_<name_of_my_bot>="1234567879:AbcD..."
Next, restart R and you are ready to use al the (simple)
functionality of the depigner
package, or the flexible
and complete ones from the telegram.bot
package.
invisible()
## Not run: library(depigner) start_bot_for_chat() ## End(Not run)
## Not run: library(depigner) start_bot_for_chat() ## End(Not run)
summary_interact
summary_interact( model, ref, discrete, ref_min = NULL, ref_max = NULL, level = NULL, ..., digits = 3L, p = FALSE )
summary_interact( model, ref, discrete, ref_min = NULL, ref_max = NULL, level = NULL, ..., digits = 3L, p = FALSE )
model |
A model from |
ref |
A continuous variable for which we are interested in the estimation of the OR for the various level of interaction with a discrete variable interacting with it |
discrete |
The discrete interacting variable |
ref_min |
Denominator continuous level for the Odds Ratio (i.e., the reference level), if NULL (the default) |
ref_max |
Numerator continuous level for the Odds Ratio (i.e., the target level) |
level |
A character vector of levels to show. Default (NULL) means to show all the possible levels for the discrete variable |
... |
for possible future development |
digits |
number of significant digits to print. Default is 3 Note: the |
p |
do you want also the P-value (default = FALSE) |
A data frame
library(rms) options(datadist = "dd") data("transplant", package = "survival") transplant <- transplant[transplant[["event"]] != "censored", ] %>% droplevels() dd <- datadist(transplant) lrm_mod <- lrm(event ~ rcs(age, 3) * (sex + abo) + rcs(year, 3), data = transplant ) lrm_mod summary(lrm_mod) summary_interact(lrm_mod, age, sex) summary_interact(lrm_mod, age, sex, ref_min = 60, ref_max = 80) summary_interact(lrm_mod, age, sex, ref_min = 60, ref_max = 80, digits = 5L ) summary_interact(lrm_mod, age, abo) summary_interact(lrm_mod, age, abo, level = c("A", "AB")) summary_interact(lrm_mod, age, abo, level = c("A", "AB"), p = TRUE)
library(rms) options(datadist = "dd") data("transplant", package = "survival") transplant <- transplant[transplant[["event"]] != "censored", ] %>% droplevels() dd <- datadist(transplant) lrm_mod <- lrm(event ~ rcs(age, 3) * (sex + abo) + rcs(year, 3), data = transplant ) lrm_mod summary(lrm_mod) summary_interact(lrm_mod, age, sex) summary_interact(lrm_mod, age, sex, ref_min = 60, ref_max = 80) summary_interact(lrm_mod, age, sex, ref_min = 60, ref_max = 80, digits = 5L ) summary_interact(lrm_mod, age, abo) summary_interact(lrm_mod, age, abo, level = c("A", "AB")) summary_interact(lrm_mod, age, abo, level = c("A", "AB"), p = TRUE)
Converts a summary()
object produced by Hmisc
or
by rms
packages to a tidy data frame ready to be
'pander'ed (e.g. printed on a word document after
knit
ting the source (with 'knitr').
tidy_summary(x, ..., digits = 3L) ## S3 method for class 'summary.formula.reverse' tidy_summary(x, ..., digits = 3L) ## S3 method for class 'summary.rms' tidy_summary(x, ..., digits = 3L)
tidy_summary(x, ..., digits = 3L) ## S3 method for class 'summary.formula.reverse' tidy_summary(x, ..., digits = 3L) ## S3 method for class 'summary.rms' tidy_summary(x, ..., digits = 3L)
x |
an object used to select a method, output of some summary
by |
... |
further arguments passed to or from other methods |
digits |
number of significant digits to use (default 3L). |
a [tibble][tibble::tibble-package]
tidy_summary(summary.formula.reverse)
: Tidies a summary reverse output from the
summary.formula
called with
method = "reverse"
.
tidy_summary(summary.rms)
: Convert the output of the
summary.rms
into a data frame,
reporting only the Hazard Ratio with the .95 CI and the
incremental step (for continuous variables) reference
(for categorical variables) for which the Hazard is
referred to (i.e. without s, Low, High, S.E.
and Type).
The output is supposed to be used as input to [pander][pander::pander], and contains few otherwise messy characters included for an optimal (pander) formatting.
to see the options you can pass to ...
for a custom
print, see the print section in summary.formula
.
library(Hmisc) my_summary <- summary(Species ~ ., data = iris, method = "reverse") tidy_summary(my_summary) library(rms) options(datadist = "dd") n <- 1000L set.seed(731L) age <- 50L + 12L * rnorm(n) sex <- factor(sample(c("Male", "Female"), n, rep = TRUE, prob = c(.6, .4) )) cens <- 15L * runif(n) h <- .02 * exp(.04 * (age - 50L) + .8 * (sex == "Female")) dt <- -log(runif(n)) / h e <- ifelse(dt <= cens, 1L, 0L) dt <- pmin(dt, cens) dd <- datadist(age, sex) S <- survival::Surv(dt, e) f <- rms::cph(S ~ age + sex) my_summary <- summary(f) tidy_summary(my_summary)
library(Hmisc) my_summary <- summary(Species ~ ., data = iris, method = "reverse") tidy_summary(my_summary) library(rms) options(datadist = "dd") n <- 1000L set.seed(731L) age <- 50L + 12L * rnorm(n) sex <- factor(sample(c("Male", "Female"), n, rep = TRUE, prob = c(.6, .4) )) cens <- 15L * runif(n) h <- .02 * exp(.04 * (age - 50L) + .8 * (sex == "Female")) dt <- -log(runif(n)) / h e <- ifelse(dt <= cens, 1L, 0L) dt <- pmin(dt, cens) dd <- datadist(age, sex) S <- survival::Surv(dt, e) f <- rms::cph(S ~ age + sex) my_summary <- summary(f) tidy_summary(my_summary)
Does setup necessary to use the usethis' user interfaces in your package.
This function requires the use roxygen.
* Check that the active package uses roxygen2
* Adds usethis package to "Imports" in 'DESCRIPTION'
* Imports in your namespace:
- block styles: ui_line
, ui_todo
ui_done
, ui_todo
, ui_oops
ui_info
, ui_code_block
- conditions: ui_stop
, ui_warn
- questions: ui_yeah
, ui_nope
- inline styles: ui_field
, ui_value
ui_path
, ui_code
) user interfaces
use_ui()
use_ui()
Attribution: most of the source content of this function is taken and/or adapted from the corresponding unexported function in the 'usethis' package.
## Not run: # while setup of a package use_ui() ## End(Not run)
## Not run: # while setup of a package use_ui() ## End(Not run)
This function open in Excel a data frame, returning it invisibly to be "pipe-able". The operation is done only in interactive session, so that it has no effect on pipe-chains of code executed in batch.
view_in_excel(.data)
view_in_excel(.data)
.data |
a data frame |
This function is useful for intermediate inspection of data, possibly in the middle of piped transformations.
This version: avoid unwanted execution (interactive session only), embed the correct extension in the temporary file, add BOM for Excel pleasure, and return the output invisibly, in case it is the last element of the chain.
the '.data', unchanged and invisibly
this function was originated during the conversation on Twitter started at https://twitter.com/brodriguesco/status/1447468259725434886?s=20
## Not run: four_cyl_cars <- mtcars %>% view_in_excel() %>% dplyr::filter(cyl == 4) %>% view_in_excel() four_cyl_cars ## End(Not run)
## Not run: four_cyl_cars <- mtcars %>% view_in_excel() %>% dplyr::filter(cyl == 4) %>% view_in_excel() four_cyl_cars ## End(Not run)