Skip to content

Instantly share code, notes, and snippets.

@franperezlopez
franperezlopez / codechunk
Last active May 1, 2016 23:15
r-markdown
```{r include=F}
options(width=120)
set.seed(3874)
options(error=function() {save.image(file="error.rmd.RData")})
```
---
title: "Untitled"
output: html_document
---
@franperezlopez
franperezlopez / scraper.ts
Last active December 4, 2018 05:19
nightmare + vo
const Nightmare = require ("nightmare");
const vo = require("vo");
function scrape (url: string, dataScraper: Function, urlScraper: Function,
injectJQuery: boolean = true, validate: Function = null)
{
var item : any = null, urls: any = null;
// do not show window, do not load images (reduce time to ready())
var nightmare = Nightmare({show: false, pollInterval: 800, webPreferences: {images: false}});
@franperezlopez
franperezlopez / chunk_save
Last active September 1, 2017 16:16
rMarkdown save document environment
```{r}
# save document's environment (replaces existing one)
save.image(file="housePrices.rmd.RData")
# archive (optional)
save.image(file=paste0("housePrices_", format(Sys.time(),"%d%m%y_%H%M"), ".rmd.RData"))
```
@franperezlopez
franperezlopez / load.r
Created September 1, 2017 15:50
rMarkdown load environment from document
# reset current environment (optional)
rm(list=ls())
# load environment from file
load("housePrices.rmd.RData")
@franperezlopez
franperezlopez / load.r
Created September 1, 2017 15:50
rMarkdown load environment from document
# reset current environment (optional)
rm(list=ls())
# load environment from file
load("housePrices.rmd.RData")
@franperezlopez
franperezlopez / chunk_save_error
Created September 1, 2017 15:52
rMarkdown save environment document on error
```{r}
options(error=function() {save.image(file="error.rmd.RData")})
```
@franperezlopez
franperezlopez / chunk_eval
Created September 1, 2017 15:54
rMarkdown compilation flags using variables on eval
```{r}
eval.trainModels=T
eval.pcaOptimization=T
```
```{r eval=eval.pcaOptimization, include=eval.pcaOptimization}
# code applying PCA optimization
...
@franperezlopez
franperezlopez / chunk_cache
Last active September 1, 2017 16:15
rMarkdown cache attributes
```{r rf, cache=T}
# train random forest model
```
```{r cache=T, dependson=”rf”}
# predict using random forest model
```
@franperezlopez
franperezlopez / cache_remove.r
Created September 1, 2017 15:57
rMarkdown remove cache
unlink('housePrices_cache', recursive = TRUE)