README.md

depigner

A utility package to help you deal with pigne

| | | | | |:----------------|:-------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------:| | Development | Devel version | lifecycle | last commit | | CRAN | CRAN status | downloads | downloads | | CI | R build status | Coverage status | code size |

Pigna [pìn’n’a] is the Italian word for pine cone.[^1] In jargon, it’s used to identify something (like a task…) 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 at the end you will find at least one inside it…

Overview

This package aims to provide some useful functions to be used to solve small everyday problems of coding or analyzing data with R. The hope is to provide solutions to that kind of problems which would be normally solved using quick-and-dirty (ugly and maybe even wrong) patches.

| Tools Category | Function(s) | Aim | |:-----------------------------------------|:--------------------------|:--------------------------------------------------------------------------------------------| | Harrell’s verse | tidy_summary() | pander-ready data frame from Hmisc::summary() | |   | paired_test_continuous | Paired test for continuous variable into Hmisc::summary | |   | paired_test_categorical | Paired test for categorical variable into Hmisc::summary | |   | adjust_p() | Adjusts P-values for multiplicity of tests at tidy_summary() | |   | summary_interact() | data frame of OR for interaction from rms::lrm() | |   | htypes() | Will be your variables continuous or categorical in Hmisc::describe()? | | Statistical | ci2p() | Get P-value form estimation and confidence interval | | Programming | pb_len() | Quick set-up of a progress::progress_bar() progress bar | |   | install_pkg_set() | Politely install set of packages (topic-related sets at ?pkg_sets) | |   | view_in_excel() | Open a data frame in Excel, even in the middle of a pipe chain, on interactive session only | | Development | use_ui() | Activate {usethis} user interface into your own package | |   | please_install() | Politely ask the user to install a package | |   | imported_from() | List packages imported from a package (which has to be installed) | | Telegram | start_bot_for_chat() | Quick start of a {telegram.bot} Telegram’s bot | |   | send_to_telegram() | Unified wrapper to send someRthing to a Telegram chat | |   | errors_to_telegram() | Divert all your error messages from the console to a Telegram chat | | Why not?! | gdp() | Do you have TOO much pignas in your back?! … try this out ;-) |

Installation

You can install the released version of {depigner} from CRAN with:

install.packages("depigner")

You can install the development version from GitHub calling:

# install.packages("devtools")
devtools::install_github("CorradoLanera/depigner")

Next, you can attach it to your session by:

library(depigner)
#> Welcome to depigner: we are here to un-stress you!

Provided Tools

Harrell’s Verse Tools

Currently it is tested for method reverse only:

library(rms)
#> Loading required package: Hmisc
#> 
#> Attaching package: 'Hmisc'
#> The following objects are masked from 'package:base':
#> 
#>     format.pval, units
#> Loading required package: survival
#> Loading required package: lattice
#> Loading required package: ggplot2
#> Loading required package: SparseM
#> 
#> Attaching package: 'SparseM'
#> The following object is masked from 'package:base':
#> 
#>     backsolve
  options(datadist = 'dd')
library(survival)
library(pander)

dd <- datadist(iris)
my_summary <- summary(Species ~., data = iris, method = "reverse")
tidy_summary(my_summary) %>% 
  pander()

|   | setosa (N=50) | versicolor (N=50) | virginica (N=50) | |:------------:|:-----------------:|:-----------------:|:-----------------:| | Sepal.Length | 4.800/5.000/5.200 | 5.600/5.900/6.300 | 6.225/6.500/6.900 | | Sepal.Width | 3.200/3.400/3.675 | 2.525/2.800/3.000 | 2.800/3.000/3.175 | | Petal.Length | 1.400/1.500/1.575 | 4.000/4.350/4.600 | 5.100/5.550/5.875 | | Petal.Width | 0.2/0.2/0.3 | 1.2/1.3/1.5 | 1.8/2.0/2.3 |



dd <<- datadist(heart) # this to face a package build issue,
                       # use standard `<-` into analyses
surv <- Surv(heart$start, heart$stop, heart$event)
f    <- cph(surv ~ age + year + surgery, data = heart)
my_summary <- summary(f)
tidy_summary(my_summary) %>% 
  pander()

|   | Diff. | HR | Lower 95% CI | Upper 95% CI | |:-------:|:-----:|:------:|:------------:|:------------:| | age | 10.69 | 1.336 | 1.009 | 1.767 | | year | 3.374 | 0.6104 | 0.3831 | 0.9727 | | surgery | 1 | 0.5286 | 0.2574 | 1.085 |

data(Arthritis)
# categorical -------------------------
## two groups
summary(Treatment ~ Sex,
    data    = Arthritis,
    method  = "reverse",
    test    = TRUE,
    catTest = paired_test_categorical
)
#> 
#> 
#> Descriptive Statistics by Treatment
#> 
#> +----------+--------------------+--------------------+------------------------------+
#> |          |Placebo             |Treated             |  Test                        |
#> |          |(N=43)              |(N=41)              |Statistic                     |
#> +----------+--------------------+--------------------+------------------------------+
#> |Sex : Male|           26%  (11)|           34%  (14)|Chi-square=5.92 d.f.=1 P=0.015|
#> +----------+--------------------+--------------------+------------------------------+
## more than two groups
summary(Improved ~ Sex,
    data    = Arthritis,
    method  = "reverse",
    test    = TRUE,
    catTest = paired_test_categorical
)
#> 
#> 
#> Descriptive Statistics by Improved
#> 
#> +----------+-----------------+-----------------+-----------------+------------------------+
#> |          |None             |Some             |Marked           |  Test                  |
#> |          |(N=42)           |(N=14)           |(N=28)           |Statistic               |
#> +----------+-----------------+-----------------+-----------------+------------------------+
#> |Sex : Male|        40%  (17)|        14%  ( 2)|        21%  ( 6)|chi2=1.71 d.f.=3 P=0.634|
#> +----------+-----------------+-----------------+-----------------+------------------------+

# continuous --------------------------
## two groups
summary(Species ~.,
    data    = iris[iris$Species != "setosa",],
    method  = "reverse",
    test    = TRUE,
    conTest = paired_test_continuous
)
#> 
#> 
#> Descriptive Statistics by Species
#> 
#> +------------+---------------------+---------------------+------------------------+
#> |            |versicolor           |virginica            |  Test                  |
#> |            |(N=50)               |(N=50)               |Statistic               |
#> +------------+---------------------+---------------------+------------------------+
#> |Sepal.Length|    5.600/5.900/6.300|    6.225/6.500/6.900| t=-5.28 d.f.=49 P<0.001|
#> +------------+---------------------+---------------------+------------------------+
#> |Sepal.Width |    2.525/2.800/3.000|    2.800/3.000/3.175| t=-3.08 d.f.=49 P=0.003|
#> +------------+---------------------+---------------------+------------------------+
#> |Petal.Length|    4.000/4.350/4.600|    5.100/5.550/5.875|t=-12.09 d.f.=49 P<0.001|
#> +------------+---------------------+---------------------+------------------------+
#> |Petal.Width |       1.2/1.3/1.5   |       1.8/2.0/2.3   |t=-14.69 d.f.=49 P<0.001|
#> +------------+---------------------+---------------------+------------------------+
## more than two groups
summary(Species ~.,
    data    = iris,
    method  = "reverse",
    test    = TRUE,
    conTest = paired_test_continuous
)
#> 
#> 
#> Descriptive Statistics by Species
#> 
#> +------------+--------------------+--------------------+--------------------+-----------------------+
#> |            |setosa              |versicolor          |virginica           |  Test                 |
#> |            |(N=50)              |(N=50)              |(N=50)              |Statistic              |
#> +------------+--------------------+--------------------+--------------------+-----------------------+
#> |Sepal.Length|   4.800/5.000/5.200|   5.600/5.900/6.300|   6.225/6.500/6.900| F=30.55 d.f.=2 P<0.001|
#> +------------+--------------------+--------------------+--------------------+-----------------------+
#> |Sepal.Width |   3.200/3.400/3.675|   2.525/2.800/3.000|   2.800/3.000/3.175| F=12.63 d.f.=2 P<0.001|
#> +------------+--------------------+--------------------+--------------------+-----------------------+
#> |Petal.Length|   1.400/1.500/1.575|   4.000/4.350/4.600|   5.100/5.550/5.875|F=322.89 d.f.=2 P<0.001|
#> +------------+--------------------+--------------------+--------------------+-----------------------+
#> |Petal.Width |      0.2/0.2/0.3   |      1.2/1.3/1.5   |      1.8/2.0/2.3   |F=234.21 d.f.=2 P<0.001|
#> +------------+--------------------+--------------------+--------------------+-----------------------+
my_summary <- summary(Species ~., data = iris,
  method = "reverse",
  test = TRUE
)

tidy_summary(my_summary, prtest = "P") %>%
  adjust_p()
#> ✔ P adjusted with BH method.
#> # A tibble: 4 × 5
#>   `&nbsp;`     `setosa \n(N=50)`   `versicolor \n(N=50)` `virginica \n(N=50)`
#>   <chr>        <chr>               <chr>                 <chr>               
#> 1 Sepal.Length "4.800/5.000/5.200" "5.600/5.900/6.300"   "6.225/6.500/6.900" 
#> 2 Sepal.Width  "3.200/3.400/3.675" "2.525/2.800/3.000"   "2.800/3.000/3.175" 
#> 3 Petal.Length "1.400/1.500/1.575" "4.000/4.350/4.600"   "5.100/5.550/5.875" 
#> 4 Petal.Width  "   0.2/0.2/0.3"    "   1.2/1.3/1.5"      "   1.8/2.0/2.3"    
#> # ℹ 1 more variable: `P-value` <chr>
data("transplant", package = "survival")
censor_rows <- transplant[['event']] != 'censored' 
transplant <- droplevels(transplant[censor_rows, ])

dd <<- datadist(transplant) # this to face a package build issue,
                            # use standard `<-` into analyses

lrm_mod <- lrm(event ~ rcs(age, 3)*(sex + abo) + rcs(year, 3),
  data = transplant
)
summary_interact(lrm_mod, age, abo) %>%
  pander()

|   | Low | High | Diff. | Odds Ratio | Lower 95% CI | Upper 95% CI | |:--------:|:---:|:----:|:-----:|:----------:|:------------:|:------------:| | age - A | 43 | 58 | 15 | 1.002 | 0.557 | 1.802 | | age - B | 43 | 58 | 15 | 1.817 | 0.74 | 4.463 | | age - AB | 43 | 58 | 15 | 0.635 | 0.186 | 2.169 | | age - O | 43 | 58 | 15 | 0.645 | 0.352 | 1.182 |


summary_interact(lrm_mod, age, abo, p = TRUE) %>%
  pander()

|   | Low | High | Diff. | Odds Ratio | Lower 95% CI | Upper 95% CI | P-value | |:--------:|:---:|:----:|:-----:|:----------:|:------------:|:------------:|:-------:| | age - A | 43 | 58 | 15 | 1.002 | 0.557 | 1.802 | 0.498 | | age - B | 43 | 58 | 15 | 1.817 | 0.74 | 4.463 | 0.137 | | age - AB | 43 | 58 | 15 | 0.635 | 0.186 | 2.169 | 0.728 | | age - O | 43 | 58 | 15 | 0.645 | 0.352 | 1.182 | 0.883 |

htypes(mtcars)
#>    mpg    cyl   disp     hp   drat     wt   qsec     vs     am   gear   carb 
#>  "con" "none"  "con"  "con"  "con"  "con"  "con"  "cat"  "cat" "none" "none"

desc <- Hmisc::describe(mtcars)
htypes(desc)
#>    mpg    cyl   disp     hp   drat     wt   qsec     vs     am   gear   carb 
#>  "con" "none"  "con"  "con"  "con"  "con"  "con"  "cat"  "cat" "none" "none"
htype(desc[[1]])
#> [1] "con"
is_hcat(desc[[1]])
#> [1] FALSE
is_hcon(desc[[1]])
#> [1] TRUE

Statistical Tools

ci2p(1.125, 0.634,  1.999, log_transform = TRUE)
#> [1] 0.367902

Programming Tools

pb <- pb_len(100)

for (i in 1:100) {
    Sys.sleep(0.1)
    tick(pb, paste("i = ", i))
}
install_pkg_set() # this install the whole `?pkg_all`
install_pkg_set(pkg_stan)

?pkg_sets
four_cyl_cars <- mtcars %>%
  view_in_excel() %>%
  dplyr::filter(cyl == 4) %>%
  view_in_excel()

four_cyl_cars

Development Tools

# in the initial setup steps of the development of a package
use_ui()
a_pkg_i_miss <- setdiff(available.packages(), installed.packages())[[1]]
please_install(a_pkg_i_miss)
imported_from("depigner")
#>  [1] "desc"         "dplyr"        "fs"           "ggplot2"      "Hmisc"       
#>  [6] "magrittr"     "progress"     "purrr"        "readr"        "rlang"       
#> [11] "rms"          "rprojroot"    "stats"        "stringr"      "telegram.bot"
#> [16] "tibble"       "tidyr"        "usethis"      "utils"

Telegram Tools

# Set up a Telegram bot. read `?start_bot_for_chat`
start_bot_for_chat()

# Send something to telegram
send_to_telegram("hello world")

library(ggplot2)
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)

# Divert output errors to the telegram bot
errors_to_telegram()

Why Not?!

gdp(7)

Feature request

If you need some more features, please open an issue here.

Bug reports

If you encounter a bug, please file a reprex (minimal reproducible example) here.

Code of Conduct

Please note that the depigner project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Acknowledgements

The {depigner}’s logo was lovely designed by Elisa Sovrano.

Reference

[^1]: You can find all the possible meanings of pigna here, and you can listen how to pronounce it here. Note: the Italian plural for “pigna” is “pigne” [pìn’n’e].



Try the depigner package in your browser

Any scripts or data that you put into this service are public.

depigner documentation built on April 24, 2023, 5:08 p.m.