knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
Miscellaneous function, color palettes, collected doing modelling, many trivial ones.
The development version from GitHub with:
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 viewingmore(LETTERS[rep(1:26, each=1000)])
pick
: wrapper of grep
tp pick element with regexquery_label
: search variable labels on labelled data (e.g.
haven::read_dta
)# 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
)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 separatelyg <- iris %>% ggplot(aes(Sepal.Length)) + geom_histogram() + facet_wrap(~Species) facet_unwrap(g)
allot
: ->
right assign with pipe (experimental - use interactive only)# 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.frametake_note
: Write a note to fileunkount
: Uncounting data frame using a weightssurv_split
to split survival time for immediate death modelscreen_to_file
: write object on screen to a file, e.g. get contents of a functionchar
: quoting automaticchar(a, b, c) # [1] "a" "b" "c"
bracket
: put bracket around a textbrowse
: Show data frame in browsercd
: replicate some features of bash cdcd() # Moved from: /Users/knguyen/Code/R/ktools # to ~ cd('-') # Moved from: /Users/knguyen # to /Users/knguyen/Code/R/ktools
AR2_Q
MakeADFunSafe
double_logistic
: Double logistic functionfindInterval2
: findInterval and return factor with labelfractional_poly
: find best fit fractional polynomial using GLMkut
: Cut but automatically include min and max data's valuekompile
: compile TMB with extra ktools
's C++
headers lsSize
: list objects with sizenapply
: n(amed)apply: lapply but automatic add names to outputpfrankCopula
: Frank copulas probtmb_fixit
: TMB fix parametersnullspace_penalty()
name2list(c(x = 1, abc = 2))
Let search engines do the work of documenting.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.