Suppose you have a long running calculation:
f <- function(x) {
message("Evaluating slow function")
Sys.sleep(5) # sleep 5 seconds to simulate long running time
x
}| #!/bin/sh | |
| ## Information | |
| ## http://carlo-hamalainen.net/blog/2007/12/11/installing-minion-pro-fonts/ | |
| ## http://www.ctan.org/tex-archive/fonts/mnsymbol/ | |
| ## 0: Install | |
| ## http://www.lcdf.org/type/ | |
| ## I used --without-kpathsea to configure (with MacTeX 2011): | |
| ## | |
| ## ./configure --without-kpathsea |
| #!/usr/bin/Rscript | |
| library(tools) | |
| library(knitr) | |
| library(sowsear) | |
| opts_knit$set(progress = FALSE, verbose = FALSE) | |
| ## We need a list of files and a package to start. | |
| args <- commandArgs(TRUE) | |
| package <- args[[1]] | |
| files <- args[-1] |
Suppose you have a long running calculation:
f <- function(x) {
message("Evaluating slow function")
Sys.sleep(5) # sleep 5 seconds to simulate long running time
x
}| ## Follow steps in original post to download files using ghrabber. | |
| ## https://github.com/trestletech/rhistory/ | |
| ## Then load as one big character vector (161828 entries on 21 Feb 2013). | |
| dat <- unlist(lapply(dir("fetched", full=TRUE), readLines)) | |
| ## Count uses of TRUE / FALSE | |
| length(grep("\\b(TRUE|FALSE)\\b", dat)) # 4389 | |
| ## and of T / F shortcuts | |
| length(dat[grep("\\b[TF]\\b", dat)]) # 2432 |
| library(testthat) | |
| ## This works but won't correct labels: | |
| not <- function(f) { | |
| function(...) { | |
| res <- f(...) | |
| res$passed <- !res$passed | |
| res | |
| } | |
| } |
| Stargazer and R Markdown to LaTeX | |
| ======================================================== | |
| If you're using LaTeX, then use the Sweave-like knitr opions here instead. The `results='asis'` means that knitr won't do any processing on the output, so when you run this it produces a bunch of gobbledygook. | |
| ```{r} | |
| library(stargazer) | |
| ``` |
| ## OK, this turned out to be more complicated than I would have | |
| ## thought. I feel that this approach *should* work, but it confuses | |
| ## R's multi-panel plots: | |
| ## Smaller margins, plus a top margin | |
| par(mar=c(3.1, 3.1, .5, .5), oma=c(0, 0, 1.5, 0), mfrow=c(2, 2)) | |
| ## Plot dummy data | |
| plot(1:10) |
| ## Captures a variable 'n' in the local scope of the returned | |
| ## function. When you run that function it increments the counter and | |
| ## prints its current value. | |
| make.counter <- function(start=0) { | |
| n <- start | |
| function() { | |
| n <<- n + 1 | |
| message(sprintf("counter value is %d", n)) | |
| } | |
| } |
| #include <vector> | |
| // [[Rcpp::export]] | |
| double or_cpp(std::vector<double> x) { | |
| double tot = 1.0; | |
| for ( size_t i = 0; i < x.size(); i++ ) | |
| tot *= (1 - x[i]); | |
| return 1 - tot; | |
| } | |
| /* |
| """ | |
| Exports Issues from a specified repository. | |
| Uses basic authentication (Github username + password) to retrieve Issues | |
| from a repository that username has access to. Supports Github API v3. | |
| From: | |
| https://gist.github.com/unbracketed/3380407 | |
| """ | |
| import requests |