Last updated: 2017-02-08
Code version: ed2aae2
library("workflowr")
library("ggplot2")
theme_set(theme_bw())
Generate some values from a normal distribution.
mean_value <- sample(1:10, size = 1)
normal_dist <- rnorm(5, mean = mean_value)
Archive them.
wflow_archive(mean_value, normal_dist, subdir = "archive.Rmd")
Archive files will be saved in ../archive/archive.Rmd
Restore them.
restored <- wflow_restore(mean_value, normal_dist, subdir = "archive.Rmd")
Restoring files from ../archive/archive.Rmd
str(restored)
List of 2
$ mean_value :List of 5
..$ 393a8dc: int 3
..$ 4703321: int 10
..$ 74dd2e3: int 7
..$ c207e3c: int 7
..$ ed2aae2: int 10
$ normal_dist:List of 5
..$ 393a8dc: num [1:5] 3.36 3.68 3.31 2.6 3.97
..$ 4703321: num [1:5] 9.08 10.28 8.56 10.2 10.32
..$ 74dd2e3: num [1:5] 7.47 7.15 8.54 8.34 6.81
..$ c207e3c: num [1:5] 7.84 5.63 7.69 7.01 6.84
..$ ed2aae2: num [1:5] 9.31 9.53 10.56 11.09 9.38
Analyze them.
mean_set <- unlist(restored$mean_value)
mean_estimate <- sapply(restored$normal_dist, function(x) mean(x))
error <- abs(mean_set - mean_estimate)
d <- data.frame(mean_set, error, commit = names(error))
ggplot(d, aes(x = mean_set, y = error, label = commit)) +
geom_text() +
labs(x = "Actual mean",
y = "Absolute error between actual and estimated mean",
title = "Relationship between the mean, its estimation error, and commit")
The function currently use non-standard evaluation tricks so that the objects can be directly passed (instead of creating a named list). This works great unless they are embedded inside of another function. Do we expect it will be common to embed these functions within other functions? If yes, we need to make standard evaluation options avaialable as well (e.g. dplyr has the non-standard evalation function select
and the corresponding standard evalation select_
for use inside functions).
What to restore beyond the sha1 for each commit? The commit message? The date?
How to commit the archive files? Have wflow_commit
check the archive directory? This may need to wait until a configuration file is implemented.
What about the files created during testing? These will have the wrong commit. Need some mechanism for detecting and removing archives created by files with non-saved changes.
sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_2.1.0 workflowr_0.3.0 rmarkdown_1.3
loaded via a namespace (and not attached):
[1] Rcpp_0.12.9 digest_0.6.10 rprojroot_1.2 plyr_1.8.4
[5] grid_3.3.2 gtable_0.1.2 backports_1.0.5 git2r_0.18.0
[9] magrittr_1.5 scales_0.4.0 evaluate_0.10 stringi_1.1.1
[13] labeling_0.3 tools_3.3.2 stringr_1.1.0 munsell_0.4.3
[17] yaml_2.1.14 colorspace_1.2-6 htmltools_0.3.5 knitr_1.15.1
This R Markdown site was created with workflowr