This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#< 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(htmlwidgets) | |
library(knitr) | |
md.code = ' | |
There are the annoying <!–html_preserve–> lines... | |
```{r "mychunk"} | |
textInput("myInput","Enter text","Hello World") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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", ...) | |
} |