Skip to content

Instantly share code, notes, and snippets.

View martinctc's full-sized avatar
🔥
Packaging up my workflows

Martin Chan martinctc

🔥
Packaging up my workflows
View GitHub Profile
@martinctc
martinctc / pkg_summary.R
Last active July 25, 2020 08:08
[Run a summary of functions and the associated description from a loaded package] #R
#' Run a summary of functions and the associated description
#' for a loaded package
#'
#' @param package_name String providing the name of the loaded package, e.g. surveytoolbox
#'
#' @examples
#' \dontrun{
#' pkg_summary("surveytoolbox")
#' pkg_summary("wpa")
#' pkg_summary("rwa")
@martinctc
martinctc / minimal_html_report.R
Created April 27, 2020 15:48
[Minimal Function to generate HTML report using RMarkdown] #R
## This is a minimal example to show how you can create a
## function that generates HTML reports using RMarkdown.
##
## This uses a list-pmap workflow so you can input lists
## as arguments and dynamically produce a RMarkdown that
## is only limited by the length of your lists.
##
## The example below outputs a table and two plots from
## `iris`.
@martinctc
martinctc / ForceNetwork_example.R
Created April 22, 2020 09:53
[ForceNetwork network example with {networkD3}] #R
library(tidyverse)
library(networkD3)
## Nodes data frame describing all the nodes in the network
## The first entry in nodes dataframe is node 0, the next entry is node 1 and so on.
## The nodes dataframe must be sorted according to this sequence.
## This is the only way to tie the nodes dataframe to the links dataframe.
TestNodes <- data.frame(name = c("Alpha",
"Beta",
"Cat",
@martinctc
martinctc / lolololololol.R
Created April 10, 2020 11:40
[Generate lolololololol in #R]
paste(rep("l", exp(10)), collapse = "o")
@martinctc
martinctc / list_functions.R
Created April 2, 2020 16:48
[List all functions in a package and return as a tibble]
lsf.str("package:wpa") %>%
as.list() %>%
unlist() %>%
as_tibble()
@martinctc
martinctc / card_hover_effect.html
Created March 4, 2020 14:17
[Card Hover Flip Effect] #HTML #CSS #JS
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js" type="text/javascript"></script>
</head>
<style>
body {
background: #000;
font-family: arial, san-serif;
color: #fff;
}
@martinctc
martinctc / rowwise_example.R
Created March 2, 2020 13:03
[Rowwise example in R] #R
library(tidyverse)
iris %>%
rowwise() %>%
mutate(any = any(c(Sepal.Length, Sepal.Width) > 5))
@martinctc
martinctc / varimax-pca.R
Created February 24, 2020 18:38
[Varimax rotated PCA in R] #R
library(tidyverse)
library(FactoMineR)
iris %>%
select(-Species) %>%
PCA(graph = FALSE) -> res
# FactoMineR does not return the loadings but the coordinates of the variables
# You can divide the results of PCA by the square root of the eigenvalue of each dimension to recover the loadings
@martinctc
martinctc / four-pm.bat
Created February 18, 2020 17:55
[Make it 4 pm] #CommandLine
time 16:00:00
@martinctc
martinctc / tidy_rCharts.R
Created February 13, 2020 18:08
[tidy implementation of rCharts package] #R
library(tidyverse)
library(rCharts) # https://ramnathv.github.io/rCharts/
HairEyeColor %>%
as_tibble() %>%
filter(Sex == "Male") %>%
nPlot(n ~ Hair,
group = 'Eye',
data = .,
type = 'multiBarChart')