Skip to content

Instantly share code, notes, and snippets.

View cgpu's full-sized avatar
:octocat:

Christina Chatzipantsiou cgpu

:octocat:
View GitHub Profile
@cgpu
cgpu / tRee.R
Created December 1, 2018 07:26
@jennybc twee() renamed
# original script from @jennybc but wanted to change function name
# original source: https://gist.github.com/jennybc/2bf1dbe6eb1f261dfe60
## quick-and-dirty ersatz Unix tree command in R
## inspired by this one-liner:
## ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
## found here (among many other places):
## http://serverfault.com/questions/143954/how-to-generate-an-ascii-representation-of-a-unix-file-hierarchy
tRee <- function(path = getwd(), level = Inf) {
@cgpu
cgpu / DTtabler.R
Last active December 5, 2018 18:57
Interactive DataTabale
# Creates interactive datatable
# EDIT: Found how to add save buttons (cc: augmented dom var)
# Check here: https://stackoverflow.com/questions/33432174/how-to-set-multiple-option-list-and-extensions-in-dtdatatable/35200721#35200721
DTtabler <- function(file = file,
nDigits_after_decimal = 2){ # absolut path to file
@cgpu
cgpu / batchInstaller.R
Last active December 15, 2018 22:04
Takes as input a lists of R package names as chr eg. c("RMySQL") if one package, c("RMySQL", "igraph")
# Motivation of including extra code snippet:
# Annoying warning message spammer repo of the day:
# CRANextra = "http://www.stats.ox.ac.uk/pub/RWin"
batchInstaller <- function(list_of_packages ,
cpuse = parallel::detectCores() - 2){
options(repos = (CRAN = "https://cran.rstudio.com/"))
# Stack gem here: https://stackoverflow.com/questions/4090169/elegant-way-to-check-for-missing-packages-and-install-them
@cgpu
cgpu / tables_with_images_inmarkdown.md
Last active January 30, 2019 15:11
Markdown: Make a table with images in cells and neat column names

Make a table with images in cells and neat column names

Found here

ES6 with JS ES6 logo ES6 Syntax
@cgpu
cgpu / datatableR.R
Last active January 10, 2019 17:43
Interactive datatable uing the {DT} R package. Takes as input a dataframe object.
# Creates interactive datatable
# EDIT: Found how to add save buttons (cc: augmented dom var)
# Check here: https://stackoverflow.com/questions/33432174/how-to-set-multiple-option-list-and-extensions-in-dtdatatable/35200721#35200721
interactivDataTabler <- function(df = df,
nDigits_after_decimal = 2,
header_color = "#0199F3",
caption = ""){ # absolut path to file
# A GET request for retrieving all projects
import requests
url = "http://api.lifebit.ai/projects"
payload = ""
headers = {
'apikey': "HO000000PMqh60000000aDIJxgkRKnUllWXU",
}
@cgpu
cgpu / tibble_dplyr_aggregating_tricks_group_by.R
Created March 10, 2019 15:57
Aggreagate information and count observations per categorical variable label
# >_ Install tidyverse and use many cores else we will wait forever:
percentage_cpu = 0.75
if (!require("tidyverse")) install.packages("tidyverse", Ncpus = floor(percentage_cpu * parallel::detectCores()))
# Load the whole tidyvrse - totally unnecessary btw (dpdlyr will suffice)
library(tidyverse)
# Convert dataframe to tibble for the group_by etc functions to work
iris_tbl <- tibble::as_data_frame(iris)
@cgpu
cgpu / staRter.R
Last active April 1, 2019 18:52
Install packages essential command triplet
percentage_cpu = 0.75
if (!require("parallel")) install.packages("parallel")
if (!require("devtools", quietly = TRUE)) install.packages("devtools", Ncpus = floor( percentage_cpu * (parallel::detectCores() )))
devtools::source_url("http://bit.ly/mr_installoader")
@cgpu
cgpu / columnRenameR.R
Created March 18, 2019 20:14
Rename in place a column name in an R dataframe
# SO help from here: https://stackoverflow.com/questions/6081439/changing-column-names-of-a-data-frame
colnames(dataframe)[which(names(dataframe) == "columnName")] <- "newColumnName"