Tristan Mahr July 28, 2016
I am finalizing a manuscript. I wrote the whole thing in RMarkdown. Here is some of the first four paragraphs of the outputted Markdown file.
library("stringr")
all_lines <- readr::read_lines("reports/00_report.md")| compute_bias <- function(looks, window, t_col = "Time", aoi_col = "GazeByImageAOI", sample_rate = NULL) { | |
| # Create filtering expression by plugging in the name of the "Time" column | |
| interp <- lazyeval::interp | |
| pred <- interp(~ between(x, min(w), max(w)), x = as.name(t_col), w = window) | |
| # Keep just looks in range defined by window | |
| subtrial <- looks %>% filter_(pred) | |
| # Make sure that there is only set of looks in the data | |
| window_times <- subtrial[[t_col]] |
| sample_n_groups <- function(df, n, group_keys = as.character(groups(df))) { | |
| # Remember original grouping | |
| group_keys_orig <- as.character(groups(df)) | |
| stopifnot(length(group_keys) != 0) | |
| df_sub <- df %>% | |
| # Keep just the grouping columns | |
| group_by_(.dots = group_keys) %>% | |
| select(one_of(group_keys)) %>% | |
| distinct %>% |
| # quick gantt diagrams of a trial of an eyetracking experiment | |
| library("dplyr") | |
| library("ggplot2") | |
| # describe each event | |
| trial_events <- list() | |
| trial_events$warmup <- list( | |
| duration = 2000, | |
| see = "four images", |
| --- | |
| title: "knitr todos" | |
| author: "Tristan Mahr" | |
| date: "February 25, 2016" | |
| output: | |
| html_document: | |
| keep_md: yes | |
| --- | |
| ```{r} |
| ``` r | |
| library("dplyr", warn.conflicts = FALSE) | |
| iris %>% select(Species, starts_with("Color")) %>% head | |
| #> Species | |
| #> 1 setosa | |
| #> 2 setosa | |
| #> 3 setosa | |
| #> 4 setosa | |
| #> 5 setosa |
| library("ggplot2") | |
| library("dplyr") | |
| # Some toy data | |
| davis <- car::Davis %>% | |
| filter(100 < height) | |
| # Fit a model and estimate mean at five points | |
| m <- lm(weight ~ height, davis) | |
| newdata <- data_frame(height = c(15:19 * 10)) |
| library("stringr") | |
| # # Maybe unescape brackets? | |
| # str_replace("\\[", "\\\\\\[", "[") | |
| # str_replace_all(lines_to_check[139], "\\\\\\[", "[") | |
| # # enforce_nonbreaking? | |
| # lines_to_check %>% | |
| # str_replace_all(" = ", " = ") %>% |
| library("dplyr") | |
| only_if <- function(data, condition, pipeline) { | |
| if (condition) { | |
| pipeline(data) | |
| } else { | |
| data | |
| } | |
| } |
| my_dir <- tempdir() | |
| readr::write_csv(iris, file.path(my_dir, "iris1.csv")) | |
| readr::write_csv(iris, file.path(my_dir, "iris2.csv")) | |
| readr::write_csv(iris, file.path(my_dir, "iris3.csv")) | |
| readr::write_csv(iris, file.path(my_dir, "iris4.csv")) | |
| file_paths <- list.files(my_dir, pattern = "iris", full.names = TRUE) | |
| # Force an error so safely() does something | |
| file.remove(file.path(my_dir, "iris3.csv")) |