-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
138 lines (111 loc) · 3.5 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# ktools <img src='man/figures/logo.png' align="right" height="120" />
<!-- badges: start -->
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
Miscellaneous function, color palettes, collected doing modelling, many trivial ones.
## Installation
The development version from [GitHub](https://github.com/) with:
``` r
devtools::install_github("kklot/ktools")
```
Examples of what inside:
- `more`: View a big object in a pager view similar to `bash more`, press `q` to
quit viewing
```r
more(LETTERS[rep(1:26, each=1000)])
```
- `pick`: wrapper of `grep` tp pick element with regex
- `query_label`: search variable labels on labelled data (e.g.
`haven::read_dta`)
```r
# query KAIS surveys
query_label(b1, "cmc")
# name label
# 1: qhint Date of interview (CMC)
# 2: q102 Date of birth (CMC)
# 3: q212 Date of birth for last child (CMC)
# 4: q318 Date of birth for last child (CMC)
```
- `query_name`: search name on a data (e.g. `haven::read_dta`)
```r
query_name(b2, "weight")
# name label
# 1: rawiweight
# 2: rawbweight
# 3: aiweight
# 4: abweight
```
- `facet_unwrap`: unwrap a ggplot2::facet_wrap plot to view or save separately
```r
g <- iris %>%
ggplot(aes(Sepal.Length)) +
geom_histogram() +
facet_wrap(~Species)
facet_unwrap(g)
```
- `allot`: `->` right assign with pipe (**experimental - use interactive only**)
```r
# these two are equivalent
a <- tibble(x = 1)
tibble(x = 1) %>% allot(a)
```
- `recode_if`: like `case_when` when you want to keep original data (`TRUE ~ original`)
- `rename`: rename a column in data.frame
- `take_note`: Write a note to file
- `unkount`: Uncounting data frame using a weights
- `surv_split` to split survival time for immediate death model
- `screen_to_file`: write object on screen to a file, e.g. get contents of a function
- `char`: quoting automatic
```r
char(a, b, c)
# [1] "a" "b" "c"
```
- `bracket`: put bracket around a text
- `browse`: Show data frame in browser
- `cd`: replicate some features of bash cd
```r
cd()
# Moved from: /Users/knguyen/Code/R/ktools
# to ~
cd('-')
# Moved from: /Users/knguyen
# to /Users/knguyen/Code/R/ktools
```
- Generate AR(2) precision matrix
```r
AR2_Q
```
- MakeADFun safely terminated if there is a bound error
```r
MakeADFunSafe
```
- `double_logistic`: Double logistic function
- `findInterval2`: findInterval and return factor with label
- `fractional_poly`: find best fit fractional polynomial using GLM
- `kut`: Cut but automatically include min and max data's value
- `kompile`: compile TMB with extra `ktools`'s `C++` headers
- `lsSize`: list objects with size
- `napply`: n(amed)apply: lapply but automatic add names to output
- `pfrankCopula`: Frank copulas prob
- `tmb_fixit`: TMB fix parameters
- NullSpace penalty
```r
nullspace_penalty()
```
```r
name2list(c(x = 1, abc = 2))
```
Let search engines do the work of documenting.