Skip to content

Instantly share code, notes, and snippets.

@skranz
skranz / slow_typing.Rmd
Created May 13, 2017
An example Rmd file where editing is very slow in RStudio (Version 1.1.230) on my Windows 8.1 Notebook
View slow_typing.Rmd
#< ignore_if_included
#< settings
slides: TRUE
rtutor: FALSE
use.whiskers: TRUE
libs: [dplyr, pwt, ggplot2, plotly, tidyr,countrycode, sktools, latex2exp, stargazer]
block.libs:
chunk: armd
#quiz: shinyEventsClicker
clicker.dir: 'D:/libraries/shinyEventsClicker/apps/clickerapp'
@skranz
skranz / gist:6832705d691ca583a0ef
Created Nov 15, 2015
Example <!–html_preserve–> problem in knit2html
View gist:6832705d691ca583a0ef
library(shiny)
library(htmlwidgets)
library(knitr)
md.code = '
There are the annoying <!–html_preserve–> lines...
```{r "mychunk"}
textInput("myInput","Enter text","Hello World")
@skranz
skranz / gist:5f200040b548eef9e889
Last active Aug 29, 2015
RTutor solution file to illustrate error in shiny -> server.r -> decodeMessage -> fromJSON
View gist:5f200040b548eef9e889
# Problemset ErrorTest
## Can replicate a shiny error
## 1. Please save this code as file "ErrorTest_sol.Rmd" in your working directory
## 2. Then install RTutor as explained below
## 3. Adapt the working directory set in the code chunk "create_ps" below to your working directory
## 4. Run manually all the lines of the code chunk "create_ps" below
#< ignore
```{r "create_ps",include=TRUE , eval=TRUE}
View install_rtutor.r
# Install required packages for RTutor from CRAN and Github
# Run this code if you want to install RTutor problem sets on shinyapps.io
# Otherwise you can more easily install RTutor via
# install.packages("RTutor",repos = c("https://skranz-repo.github.io/drat/",getOption("repos")))
install.rtutor = function(update.cran=FALSE, update.github=TRUE, lib=.libPaths()[1], upgrade="never", force=TRUE,...) {
cat("\nInstall required packages from CRAN...")
# Avoid devtools::install_github warnings converted to errors
View mutate_if
# Tools to make it run
deparse_all <- function(x) {
deparse2 <- function(x) paste(deparse(x, width.cutoff = 500L), collapse = "")
vapply(x, deparse2, FUN.VALUE = character(1))
}
dt_env <- function(dt, env) {
env <- new.env(parent = env, size = 2L)
env$dt <- dt
@skranz
skranz / gist:b22b60a83f5c6ab334f7
Created May 16, 2014
mutate with possibility to select rows
View gist:b22b60a83f5c6ab334f7
mutate2 = function (.data,.where, ...) {
UseMethod("mutate2")
}
mutate2.data.frame =function (.data,.where, ...)
{
if (!missing(.where)) {
.where = substitute(.where)
dt = as.data.table(df)
df = as.data.frame(mutate_where.data.table(.data=dt,.where.call=.where,...,inplace=TRUE))
@skranz
skranz / modify
Last active Aug 29, 2015
modify, a function that wraps data.table for quick replacement of values in selected rows
View modify
library(dplyr)
library(data.table)
EmptySymbol = function() (quote(f(,)))[[2]]
get.data.table.modify.call = function(args=NULL, filter.call=NULL, by=NULL, dat.quote=quote(dt)) {
if (length(args)==1) {
com = call(":=",names(args)[1],args[[1]])
} else {
com = as.call(c(list(quote(`:=`)),args))
@skranz
skranz / s_dplyr
Created Mar 21, 2014
Wrappers to dplyr's data modification functions like arrange, select,... that work with string arguments.
View s_dplyr
# Helper functions that allow string arguments for dplyr's data modification functions like arrange, select etc.
# Author: Sebastian Kranz
# Examples are below
#' Modified version of dplyr's filter that uses string arguments
#' @export
s_filter = function(.data, ...) {
eval.string.dplyr(.data,"filter", ...)
}