This commit is contained in:
dchakro 2022-10-11 11:07:59 +03:00
parent 8a2f625bf4
commit 9f17821eb0

View file

@ -5,24 +5,32 @@
snippet beginr snippet beginr
## Description: ${1:Describe} ## Description: ${1:Describe}
`r paste("# <-", format(Sys.time(), "%a, %b %d, %Y @ %H:%M"), "->\n")` `r paste("# ----", format(Sys.time(), "%a, %b %d, %Y @ %H:%M"), "----\n")`
rm(list = ls()) rm(list = ls())
gc() gc()
library(data.table) library(data.table)
${0} ${0}
snippet comment_date snippet comment_date
`r paste("#", date(), "------------------------------\n")` `r paste("#", date(), "----------------------------\n")`
${0} ${0}
snippet rmObject snippet rmObject
rm(list=ls()[!ls() %in% c("${1:Obj1}","${2:Fun2}")]) rm(list=ls()[!ls() %in% c("${1:Obj1}","${2:Fun2}")])
${0} ${0}
snippet rmColumn snippet DFrmColumn
${1:DF}[,!colnames(${1}) %in% ${2:columnsToRemove}] ${1:DF}[,!colnames(${1}) %in% ${2:columnsToRemove}]
${0} ${0}
snippet DTrmColumn
${1:DF}[, c("${2:Col1}","${3:Col2}") := NULL]
${0}
snippet changeColumnType
changeCols <- c("${1:col1}, ${1:col2}") # define comumns to change
${3:DT}[,(changeCols):= lapply(.SD, as.factor), .SDcols = changeCols]
snippet mat snippet mat
matrix(${1:data}, nrow = ${2:rows}, ncol = ${3:cols}) matrix(${1:data}, nrow = ${2:rows}, ncol = ${3:cols})
${0} ${0}
@ -65,7 +73,7 @@ snippet replaceText
snippet not% snippet not%
'%nin%' <- Negate('%in%') '%nin%' <- Negate('%in%')
${1:var1} %in% ${2:var2} ${1:var1} %nin% ${2:var2}
snippet split snippet split
data.table::as.data.table(stringi::stri_split_fixed(str = ${1:String}, data.table::as.data.table(stringi::stri_split_fixed(str = ${1:String},
@ -97,7 +105,7 @@ snippet ggarea
${0} ${0}
snippet percentScale snippet percentScale
scale_y_continuous(breaks = seq(0, 1, by=0.25),labels = paste((seq(0, 1, by = .25)*100), "%", sep="")) scale_y_continuous(breaks = seq(0, 1, by=0.25),labels = scales::percent,limits = c(0,1))
snippet foreach snippet foreach
library(doParallel) library(doParallel)
@ -116,6 +124,15 @@ snippet foreach
${0} ${0}
snippet mclApply_block
parallel::mclapply(
X = ${1:listVar},
FUN = function(X)
${2:functioName}(X),
mc.cores = parallel::detectCores()
)
${0}
snippet multiplePlots snippet multiplePlots
## Multiple plots made in parallel and compiled into a grid ## Multiple plots made in parallel and compiled into a grid
myplots <- myplots <-
@ -188,3 +205,6 @@ snippet parallelRDS
${0} ${0}
rm(readRDS.gz,saveRDS.gz,writeRDS,loadRDS) rm(readRDS.gz,saveRDS.gz,writeRDS,loadRDS)
snippet objectSize
format(object.size(${1:Var1}), units = "MB", standard = "SI")