$ docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set R prompt to git branch name | |
# requires: devtools::install_github("gaborcsardi/prompt") | |
.prompt_grk <- function(...) { | |
dir <- if (rstudioapi::hasFun("getActiveProject") && | |
!is.null(rstudioapi::getActiveProject())) { | |
basename(rstudioapi::getActiveProject()) | |
} else { | |
basename(getwd()) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
captcha <- function(x){ | |
#input 1122 | |
#return 3 | |
#input 1111 | |
#return 4 | |
first_digit <- substr(x,1,1) | |
x <- paste0(x, first_digit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
percent <- function(data, group){ | |
group <- enquo(group) | |
data %>% | |
group_by(!!group) %>% | |
summarise(percentage = n()/nrow(data)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install RDCOMClient package | |
install.packages("RDCOMClient", repos = "http://www.omegahat.net/R") | |
library(RDCOMClient) | |
## init com api | |
OutApp <- COMCreate("Outlook.Application") | |
## create an email | |
outMail = OutApp$CreateItem(0) | |
## configure email parameter | |
outMail[["To"]] = "destination@email" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot <- ggplot(...) | |
# Log 10 transformation | |
plot + | |
scale_x_continuous(trans = "log10", | |
breaks = scales::trans_breaks("log10", function(x)10^x), | |
labels = scales::trans_format("log10", scales::math_format(10^.x))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List all files in directory which contains the file to be archived | |
files <- list.files("/path/to/file/") | |
# A distinguishing substring that allows you to identify the file to be archived | |
substring <- "some_substring" | |
# Select the file based on distinguishing substring | |
old_file <- files[which(stringr::str_detect(files, substring))] | |
# Move report to archive folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Path to script that should be sourced | |
rscript <- "path_to_script/script_name.R" | |
# To create the task | |
taskscheduleR::taskscheduler_create(taskname = basename(rscript), | |
rscript = rscript, | |
schedule = c("DAILY"), # Set schedule frequency | |
starttime = "08:00", # Set schedule start time | |
startdate = format(as.Date("2019-04-26"), "%m/%d/%Y") # Set schedule start date | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a simple example of how you can create an external log file for monitoring parallel jobs in R, using doSNOW and foreach | |
library(doSNOW) | |
library(foreach) | |
n <- 10 | |
cl <- makePSOCKcluster(5) | |
registerDoSNOW(cl) | |
writeLines(c(""), "log.txt") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
files <- dir("/path/to/your/files", full.names = T) | |
df <- files %>% | |
map(readr::read_csv) %>% | |
reduce(bind_rows) | |
NewerOlder