-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
311 lines (231 loc) · 13.4 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
---
output: github_document
bibliography: 'inst/bib/doc-pkg.bib'
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
# depigner [![](https://img.shields.io/badge/WEB site-click me-orange.svg)](https://corradolanera.github.io/depigner/) <img src="man/figures/logo.png" align="right" height="138.5"/>
A utility package to help you deal with ***pigne***
<!-- badges: start -->
| | | | |
|:----------------|:-------------------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------:|
| **Development** | [![Devel version](https://img.shields.io/badge/GitHub-0.9.1-blue.svg)](https://github.com/CorradoLanera/depigner) | [![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html#maturing) | [![last commit](https://img.shields.io/github/last-commit/CorradoLanera/depigner.svg)](https://github.com/CorradoLanera/depigner/commits/master) |
| **CRAN** | [![CRAN status](https://www.r-pkg.org/badges/version/depigner)](https://cran.r-project.org/package=depigner) | [![downloads](http://cranlogs.r-pkg.org/badges/grand-total/depigner?color=blue)](https://cran.r-project.org/package=depigner) | [![downloads](http://cranlogs.r-pkg.org/badges/last-month/depigner?color=blue)](https://cran.r-project.org/package=depigner) |
| **CI** | [![R build status](https://github.com/CorradoLanera/depigner/workflows/R-CMD-check/badge.svg)](https://github.com/CorradoLanera/depigner/actions) | [![Coverage status](https://codecov.io/gh/CorradoLanera/depigner/branch/master/graph/badge.svg)](https://codecov.io/github/CorradoLanera/depigner?branch=master) | [![code size](https://img.shields.io/github/languages/code-size/CorradoLanera/depigner.svg)](https://github.com/CorradoLanera/depigner) |
<!-- badges: end -->
> **Pigna** [*pìn'n'a*] is the Italian word for *pine cone*.^[You can find all the possible meanings of *pigna* [here](https://www.treccani.it/vocabolario/pigna/), and you can listen how to pronounce it [here](https://it.forvo.com/word/pigna/#it). Note: the Italian plural for "pigna" is "pigne" [*pìn'n'e*].] 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...
```{r include = FALSE}
knitr::opts_chunk$set(
eval = TRUE,
collapse = TRUE,
comment = "#>"
)
library(magrittr)
library(pander)
```
# 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](#harrells-verse-tools) | `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](#statistical-tools) | `ci2p()` | Get P-value form estimation and confidence interval |
| [Programming](#programming-tools) | `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](#development-tools) | `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](#telegram-tools) | `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?!](#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](https://CRAN.R-project.org) with:
``` r
install.packages("depigner")
```
You can install the development version from [GitHub](https://github.com/) calling:
```{r, eval = FALSE}
# install.packages("devtools")
devtools::install_github("CorradoLanera/depigner")
```
Next, you can attach it to your session by:
```{r}
library(depigner)
```
# Provided Tools
## Harrell's Verse Tools
- **`tidy_summary()`**: produces a data frame from the `summary()` functions provided by `{Hmisc}` [\@R-Hmisc] and `{rms}` [\@R-rms] packages ready to be `pander::pander()`ed [\@R-pander].
Currently it is tested for method *reverse* only:
```{r}
library(rms)
options(datadist = 'dd')
library(survival)
library(pander)
dd <- datadist(iris)
my_summary <- summary(Species ~., data = iris, method = "reverse")
tidy_summary(my_summary) %>%
pander()
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()
```
- **`paired_test_*()`**: Paired test for categorical/continuous variables to be used in the `summary()` of the `{Hmisc}` [\@R-Hmisc] package:
```{r}
data(Arthritis)
# categorical -------------------------
## 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
)
# continuous --------------------------
## 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
)
```
- **`adjust_p()`**: Adjust P-values of a `tidy_summary` objects:
```{r}
my_summary <- summary(Species ~., data = iris,
method = "reverse",
test = TRUE
)
tidy_summary(my_summary, prtest = "P") %>%
adjust_p()
```
- **`summary_interact()`**: Produce a data frame of OR (with the corresponding CI95%) for the interactions between different combination of a continuous variable (for which it is possible to define the reference and the target values) and (every or a selection of levels of) a categorical one in a logistic model provided by `lrm()` (from the `{rms}` package [\@R-rms]):
```{r}
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()
summary_interact(lrm_mod, age, abo, p = TRUE) %>%
pander()
```
- **`htypes()`** and friends: get/check types of variable with respect to the `{Hmisc}` ecosystem [\@R-Hmisc].
```{r}
htypes(mtcars)
desc <- Hmisc::describe(mtcars)
htypes(desc)
htype(desc[[1]])
is_hcat(desc[[1]])
is_hcon(desc[[1]])
```
## Statistical Tools
- **`ci2p()`**: compute the p-value related with a provided confidence interval:
```{r}
ci2p(1.125, 0.634, 1.999, log_transform = TRUE)
```
## Programming Tools
- **`pb_len()`**: Progress bar of given length, wrapper from the `{progress}` [\@R-progress] package:
```{r, eval=FALSE}
pb <- pb_len(100)
for (i in 1:100) {
Sys.sleep(0.1)
tick(pb, paste("i = ", i))
}
```
- **`install_pkg_set()`**: Simple and polite wrapper to install sets of packages. Moreover, `{depigner}` provides some sets already defined for common scenario in R (analyses, production, documenting, ...). See them by call `?pgk_sets`.
```{r, eval=FALSE}
install_pkg_set() # this install the whole `?pkg_all`
install_pkg_set(pkg_stan)
?pkg_sets
```
- **`view_in_excel()`**: A pipe-friendly function to view a data frame in Excel, optimal when used in the middle of a pipe-chain to see intermediate results. It works in interactive session only, so it is RMarkdown/Quarto friendly too!
```{r, eval = FALSE}
four_cyl_cars <- mtcars %>%
view_in_excel() %>%
dplyr::filter(cyl == 4) %>%
view_in_excel()
four_cyl_cars
```
## Development Tools
- **`use_ui()`**: Use `{usethis}`' user interface [\@R-usethis] in your package
```{r, eval=FALSE}
# in the initial setup steps of the development of a package
use_ui()
```
- **`lease_install()`**: This is a polite wrapper to `install.packages()` inspired (= w/ very minimal modification) by a function Hadley showed us during a course.
```{r, eval=FALSE}
a_pkg_i_miss <- setdiff(available.packages(), installed.packages())[[1]]
please_install(a_pkg_i_miss)
```
- **`imported_from()`**: If you would like to know which packages are imported by a package (eg to know which packages are required for its installation or either installed during it) you can use this function
```{r}
imported_from("depigner")
```
## Telegram Tools
- **Wrappers to simple use of Telegram's bots**: wrappers from the `{telegram.bot}` package [\@R-telegram.bot]:
```{r, eval=FALSE}
# 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()`**: A wrapper to relax
```{r, eval=FALSE}
gdp(7)
```
# Feature request
If you need some more features, please open an issue [here](https://github.com/CorradoLanera/depigner/issues).
# Bug reports
If you encounter a bug, please file a [reprex](https://github.com/tidyverse/reprex) (minimal reproducible example) [here](https://github.com/CorradoLanera/depigner/issues).
# Code of Conduct
Please note that the depigner project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
<!--=================================================================-->
# Acknowledgements
The `{depigner}`'s logo was lovely designed by [Elisa Sovrano](https://www.elisasovrano.it).
# Reference
```{r bib, include=FALSE, eval = TRUE}
# create a bib file for the R packages used in this document
knitr::write_bib(
x = c('rms', 'Hmisc', 'telegram.bot', 'progress', 'usethis',
'pander'),
file = 'inst/bib/doc-pkg.bib'
)
```