Skip to content

Instantly share code, notes, and snippets.

View ToledoEM's full-sized avatar
💭
:-)

Enrique ToledoEM

💭
:-)
View GitHub Profile
@ToledoEM
ToledoEM / parallelRDS.R
Created March 9, 2021 15:47 — forked from russellpierce/parallelRDS.R
Provided the right tools are installed, i.e. xz and pigz, will offload the compression handling to an external program and leave R free to do the data import. This ends up being quite a bit more efficient for large files. Some tweaks may be needed for operating systems other than Ubuntu; there may be additional dependencies on the github repo dr…
library(parallel)
saveRDS.xz <- function(object,file,threads=parallel::detectCores()) {
pxzAvail <- any(grepl("(XZ Utils)",system("pxz -V",intern=TRUE)))
if (pxzAvail) {
con <- pipe(paste0("pxz -T",threads," > ",file),"wb")
base::saveRDS(object, file = con)
close(con)
} else {
saveRDS(object,file=file,compress="xz")
@ToledoEM
ToledoEM / new_aes.R
Created October 22, 2019 09:08 — forked from eliocamp/new_aes.R
A way to add multiple color or fill scales to a ggplot2 plot
#' Allows to add another scale
#'
#' @param new_aes character with the aesthetic for which new scales will be
#' created
#'
new_scale <- function(new_aes) {
structure(ggplot2::standardise_aes_names(new_aes), class = "new_aes")
}
#' Convenient functions