Skip to content

Commit e91ad29

Browse files
committed
New template: AsPredicted.org questions
1 parent 466e96c commit e91ad29

File tree

13 files changed

+1061
-39
lines changed

13 files changed

+1061
-39
lines changed

DESCRIPTION

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
Package: prereg
22
Type: Package
33
Title: R Markdown Template to Preregister Scientific Studies
4-
Version: 0.1.0.9000
4+
Version: 0.1.0.9002
55
Date: 2016-2-15
66
Authors@R: c(person("Frederik", "Aust", email = "frederik.aust@uni-koeln.de", role = c("aut", "cre")))
7-
Description: The R Markdown template in this package is based on the Center
8-
for Open Science Preregistration Challenge and is, thus, particularly suited to
9-
draft preregistration documents for studies that enter the challenge.
7+
Description: The R Markdown templates in this package are based on the Center
8+
for Open Science Preregistration Challenge and the AsPredicted.org questions.
9+
They are, thus, particularly suited to draft preregistration documents for
10+
studies these programs but can also be used for internal preregistrations.
1011
URL: https://github.com/crsh/prereg
1112
BugReports: https://github.com/crsh/prereg/issues
1213
Depends:

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(aspredicted_prereg)
34
export(cos_prereg)

R/aspredicted_prereg.R

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#' AsPredicted.org template
2+
#'
3+
#' Knit a PDF document using the AsPredicted.org template
4+
#'
5+
#' @param ... additional arguments to \code{\link[rmarkdown]{pdf_document}}; \code{template} is ignored.
6+
#' @examples
7+
#' \dontrun{
8+
#' # Create R Markdown file
9+
#' rmarkdown::draft(
10+
#' "my_preregistration.Rmd"
11+
#' , "aspredicted_prereg"
12+
#' , package = "prereg"
13+
#' , create_dir = FALSE
14+
#' , edit = FALSE
15+
#' )
16+
#'
17+
#' # Render file
18+
#' rmarkdown::render("my_preregistration.Rmd")
19+
#' }
20+
#'
21+
#' @export
22+
23+
aspredicted_prereg <- function(...) {
24+
ellipsis <- list(...)
25+
if(!is.null(ellipsis$template)) ellipsis$template <- NULL
26+
27+
# Get cos_prereg template
28+
template <- system.file(
29+
"rmarkdown", "templates", "aspredicted_prereg", "resources"
30+
, "aspredicted_prereg.tex"
31+
, package = "prereg"
32+
)
33+
if(template == "") stop("No LaTeX template file found.") else ellipsis$template <- template
34+
35+
# Create format
36+
aspredicted_prereg_format <- do.call(rmarkdown::pdf_document, ellipsis)
37+
38+
## Overwrite preprocessor to set correct margin and CSL defaults
39+
saved_files_dir <- NULL
40+
41+
# Preprocessor functions are adaptations from the RMarkdown package
42+
# (https://github.com/rstudio/rmarkdown/blob/master/R/pdf_document.R)
43+
# to ensure right geometry defaults in the absence of user specified values
44+
pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir, output_dir) {
45+
# save files dir (for generating intermediates)
46+
saved_files_dir <<- files_dir
47+
48+
aspredicted_pdf_pre_processor(metadata, input_file, runtime, knit_meta, files_dir, output_dir)
49+
}
50+
51+
aspredicted_prereg_format$pre_processor <- pre_processor
52+
53+
aspredicted_prereg_format
54+
}
55+
56+
# Preprocessor functions are adaptations from the RMarkdown package
57+
# (https://github.com/rstudio/rmarkdown/blob/master/R/pdf_document.R)
58+
# to ensure right geometry defaults in the absence of user specified values
59+
60+
aspredicted_pdf_pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir, output_dir) {
61+
args <- c()
62+
63+
# Set margins if no other geometry options specified
64+
has_geometry <- function(text) {
65+
length(grep("^geometry:.*$", text)) > 0
66+
}
67+
if (!has_geometry(readLines(input_file, warn = FALSE)))
68+
args <- c(args
69+
, "--variable", "geometry:left=2.5in"
70+
, "--variable", "geometry:bottom=1.25in"
71+
, "--variable", "geometry:top=1.25in"
72+
, "--variable", "geometry:right=1in"
73+
)
74+
75+
# Use APA6 CSL citations template if no other file is supplied
76+
has_csl <- function(text) {
77+
length(grep("^csl:.*$", text)) > 0
78+
}
79+
if (!has_csl(readLines(input_file, warn = FALSE))) {
80+
csl_template <- system.file(
81+
"rmarkdown", "templates", "aspredicted_prereg", "resources", "apa6.csl"
82+
, package = "prereg"
83+
)
84+
if(csl_template == "") stop("No CSL template file found.")
85+
args <- c(args, c("--csl", rmarkdown::pandoc_path_arg(csl_template)))
86+
}
87+
88+
args
89+
}

R/cos_prereg.R

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ cos_prereg <- function(...) {
4545
# save files dir (for generating intermediates)
4646
saved_files_dir <<- files_dir
4747

48-
pdf_pre_processor(metadata, input_file, runtime, knit_meta, files_dir, output_dir)
48+
cos_pdf_pre_processor(metadata, input_file, runtime, knit_meta, files_dir, output_dir)
4949
}
5050

5151
cos_prereg_format$pre_processor <- pre_processor
@@ -58,9 +58,9 @@ cos_prereg <- function(...) {
5858
# (https://github.com/rstudio/rmarkdown/blob/master/R/pdf_document.R)
5959
# to ensure right geometry defaults in the absence of user specified values
6060

61-
pdf_pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir, output_dir) {
61+
cos_pdf_pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir, output_dir) {
6262
args <- c()
63-
63+
6464
# Set margins if no other geometry options specified
6565
has_geometry <- function(text) {
6666
length(grep("^geometry:.*$", text)) > 0
@@ -72,20 +72,19 @@ pdf_pre_processor <- function(metadata, input_file, runtime, knit_meta, files_di
7272
, "--variable", "geometry:top=1.25in"
7373
, "--variable", "geometry:right=1in"
7474
)
75-
75+
7676
# Use APA6 CSL citations template if no other file is supplied
7777
has_csl <- function(text) {
7878
length(grep("^csl:.*$", text)) > 0
7979
}
8080
if (!has_csl(readLines(input_file, warn = FALSE))) {
8181
csl_template <- system.file(
82-
"rmarkdown", "templates", "cos_prereg", "resources"
83-
, "apa6.csl"
82+
"rmarkdown", "templates", "cos_prereg", "resources", "apa6.csl"
8483
, package = "prereg"
8584
)
8685
if(csl_template == "") stop("No CSL template file found.")
8786
args <- c(args, c("--csl", rmarkdown::pandoc_path_arg(csl_template)))
8887
}
89-
88+
9089
args
91-
}
90+
}

README.Rmd

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "prereg: R Markdown Template for Preregistrations of Scientific Studies"
2+
title: "prereg: R Markdown Templates for Preregistrations of Scientific Studies"
33
output: github_document
44
---
55

@@ -8,7 +8,9 @@ output: github_document
88
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
99
[![Build status](https://travis-ci.org/crsh/prereg.svg?branch=master)](https://travis-ci.org/crsh/prereg)
1010

11-
`prereg` provides an [R Markdown](http://rmarkdown.rstudio.com/) template that facilitates authoring preregistrations of scientific studies in PDF format. The template is based on the [Center for Open Science Preregistration Challenge](https://cos.io/prereg/) template and is, thus, particularly suited to draft preregistrations that enter the challenge.
11+
`prereg` provides [R Markdown](http://rmarkdown.rstudio.com/) templates that facilitates authoring preregistrations of scientific studies in PDF format.
12+
The templates are based on the [Center for Open Science Preregistration Challenge](https://cos.io/prereg/) template and the [AsPredicted.org](http://aspredicted.org) questions.
13+
They are, thus, particularly suited to draft preregistration documents for studies these programs but can also be used for internal preregistrations.
1214

1315
If you experience any problems or have suggestions for improvements, please [open an issue](https://github.com/crsh/prereg/issues).
1416

@@ -36,7 +38,7 @@ devtools::install_github("crsh/prereg")
3638
```
3739

3840
### Create a preregistration document
39-
Once you have installed the `prereg` you can select the template when creating a new R Markdown file through the RStudio menus.
41+
Once you have installed the `prereg` you can select the templates when creating a new R Markdown file through the RStudio menus.
4042

4143
![](https://www.dropbox.com/s/y39lywyloypuncb/template_selection.png?dl=1)
4244

@@ -46,7 +48,7 @@ Once you have installed the `prereg` you can select the template when creating a
4648

4749
![](https://www.dropbox.com/s/fq6giram61bxe2m/prereg_page1.png?dl=1) ![](https://www.dropbox.com/s/cm64wpnl8la72q0/prereg_page2.png?dl=1)
4850

49-
The template file contains comments, which are invisible in the final PDF document, that provide further details on how to fill in the form.
51+
The template file contains comments that provide further details on how to fill in the form but are invisible in the final PDF document.
5052

5153
![](https://www.dropbox.com/s/ylaf6zhxri46w42/prereg_rmd.png?dl=1)
5254

@@ -57,3 +59,7 @@ If you want to use `prereg` without RStudio you can use the `rmarkdown::render`
5759
```S
5860
rmarkdown::render("mymanuscript.Rmd")
5961
```
62+
63+
## Acknowledgements
64+
The templates for the preregistrations were developed by the [Center for Open Science](https://cos.io/prereg/) and [AsPredicted.org](http://aspredicted.org), respectively.
65+
I thank both for their permission to use their material in this package.

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
prereg: R Markdown Template for Preregistrations of Scientific Studies
1+
prereg: R Markdown Templates for Preregistrations of Scientific Studies
22
================
33

44
[![CRAN status](http://www.r-pkg.org/badges/version/prereg)](https://cran.r-project.org/web/packages/prereg/index.html) [![Download counter](http://cranlogs.r-pkg.org/badges/prereg)](https://cran.r-project.org/web/packages/prereg/index.html) [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![Build status](https://travis-ci.org/crsh/prereg.svg?branch=master)](https://travis-ci.org/crsh/prereg)
55

6-
`prereg` provides an [R Markdown](http://rmarkdown.rstudio.com/) template that facilitates authoring preregistrations of scientific studies in PDF format. The template is based on the [Center for Open Science Preregistration Challenge](https://cos.io/prereg/) template and is, thus, particularly suited to draft preregistrations that enter the challenge.
6+
`prereg` provides [R Markdown](http://rmarkdown.rstudio.com/) templates that facilitates authoring preregistrations of scientific studies in PDF format. The templates are based on the [Center for Open Science Preregistration Challenge](https://cos.io/prereg/) template and the [AsPredicted.org](http://aspredicted.org) questions. They are, thus, particularly suited to draft preregistration documents for studies these programs but can also be used for internal preregistrations.
77

88
If you experience any problems or have suggestions for improvements, please [open an issue](https://github.com/crsh/prereg/issues).
99

@@ -36,7 +36,7 @@ devtools::install_github("crsh/prereg")
3636

3737
### Create a preregistration document
3838

39-
Once you have installed the `prereg` you can select the template when creating a new R Markdown file through the RStudio menus.
39+
Once you have installed the `prereg` you can select the templates when creating a new R Markdown file through the RStudio menus.
4040

4141
![](https://www.dropbox.com/s/y39lywyloypuncb/template_selection.png?dl=1)
4242

@@ -46,7 +46,7 @@ Once you have installed the `prereg` you can select the template when creating a
4646

4747
![](https://www.dropbox.com/s/fq6giram61bxe2m/prereg_page1.png?dl=1) ![](https://www.dropbox.com/s/cm64wpnl8la72q0/prereg_page2.png?dl=1)
4848

49-
The template file contains comments, which are invisible in the final PDF document, that provide further details on how to fill in the form.
49+
The template file contains comments that provide further details on how to fill in the form but are invisible in the final PDF document.
5050

5151
![](https://www.dropbox.com/s/ylaf6zhxri46w42/prereg_rmd.png?dl=1)
5252

@@ -57,3 +57,8 @@ If you want to use `prereg` without RStudio you can use the `rmarkdown::render`
5757
``` s
5858
rmarkdown::render("mymanuscript.Rmd")
5959
```
60+
61+
Acknowledgements
62+
----------------
63+
64+
The templates for the preregistrations were developed by the [Center for Open Science](https://cos.io/prereg/) and [AsPredicted.org](http://aspredicted.org), respectively. I thank both for their permission to use their material in this package.

0 commit comments

Comments
 (0)