├── .Rhistory ├── .gitignore ├── analysis ├── data │ └── DO-NOT-EDIT-ANY-FILES-IN-HERE-BY-HAND ├── templates │ ├── template.docx │ ├── journal-of-archaeological-science.csl │ ├── template.Rmd │ ├── pagebreak.lua │ ├── scholarly-metadata.lua │ └── author-info-blocks.lua └── paper │ ├── references.bib │ └── paper.Rmd ├── LICENSE ├── tests └── testthat.R ├── NAMESPACE ├── .Rbuildignore ├── rrtools.test.Rproj ├── DESCRIPTION ├── Dockerfile ├── .travis.yml ├── LICENSE.md ├── CONDUCT.md ├── CONTRIBUTING.md ├── README.md └── README.Rmd /.Rhistory: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | -------------------------------------------------------------------------------- /analysis/data/DO-NOT-EDIT-ANY-FILES-IN-HERE-BY-HAND: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2020 2 | COPYRIGHT HOLDER: Clemens Schmid 3 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(rrtools.test) 3 | 4 | test_check("rrtools.test") 5 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: fake comment so roxygen2 overwrites silently. 2 | exportPattern("^[^\\.]") 3 | -------------------------------------------------------------------------------- /analysis/templates/template.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nevrome/rrtools.test/master/analysis/templates/template.docx -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^rrtools\.test\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^README\.Rmd$ 5 | ^README-.*\.png$ 6 | ^CONDUCT\.md$ 7 | ^CONTRIBUTING\.md$ 8 | analysis 9 | ^Dockerfile$ 10 | ^\.travis\.yml$ 11 | -------------------------------------------------------------------------------- /rrtools.test.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: rrtools.test 2 | Title: What the Package Does (One Line, Title Case) 3 | Version: 0.0.0.9000 4 | Authors@R: 5 | person(given = "First", 6 | family = "Last", 7 | role = c("aut", "cre"), 8 | email = "first.last@example.com") 9 | Description: What the package does (one paragraph) 10 | License: MIT + file LICENSE 11 | ByteCompile: true 12 | Encoding: UTF-8 13 | LazyData: true 14 | Imports: bookdown, 15 | here 16 | Suggests: 17 | devtools, 18 | git2r, 19 | testthat 20 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # get the base image, the rocker/verse has R, RStudio and pandoc 2 | FROM rocker/verse:3.6.3 3 | 4 | # required 5 | MAINTAINER Your Name 6 | 7 | COPY . /rrtools.test 8 | 9 | # go into the repo directory 10 | RUN . /etc/environment \ 11 | # Install linux depedendencies here 12 | # e.g. need this for ggforce::geom_sina 13 | && sudo apt-get update \ 14 | && sudo apt-get install libudunits2-dev -y \ 15 | # build this compendium package 16 | && R -e "devtools::install('/rrtools.test', dep=TRUE)" \ 17 | # render the manuscript into a docx, you'll need to edit this if you've 18 | # customised the location and name of your main Rmd file 19 | && R -e "rmarkdown::render('/rrtools.test/analysis/paper/paper.Rmd')" 20 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Build our Docker container and R pkg on Travis 2 | 3 | env: 4 | global: 5 | - REPO=$DOCKER_USER/rrtools.test 6 | 7 | sudo: required 8 | 9 | warnings_are_errors: false 10 | 11 | language: generic 12 | 13 | services: 14 | - docker 15 | 16 | before_install: 17 | # create & run container using our dockerfile, i.e. compile pkg and render Rmd to Word doc 18 | - docker build -t $REPO . 19 | 20 | # push our custom docker container to docker hub, env vars stored on travis-ci.org 21 | after_success: 22 | - docker login -u $DOCKER_USER -p $DOCKER_PASS 23 | - export REPO=$DOCKER_USER/rrtools.test 24 | - export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH ; fi` 25 | - docker build -f Dockerfile -t $REPO:$COMMIT . 26 | - docker tag $REPO:$COMMIT $REPO:$TAG 27 | - docker tag $REPO:$COMMIT $REPO:travis-$TRAVIS_BUILD_NUMBER 28 | - docker push $REPO 29 | -------------------------------------------------------------------------------- /analysis/templates/journal-of-archaeological-science.csl: -------------------------------------------------------------------------------- 1 | 2 | 15 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2020 Clemens Schmid 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /analysis/paper/references.bib: -------------------------------------------------------------------------------- 1 | @Article{Marwick2017, 2 | author="Marwick, Ben", 3 | title="Computational Reproducibility in Archaeological Research: Basic Principles and a Case Study of Their Implementation", 4 | journal="Journal of Archaeological Method and Theory", 5 | year="2017", 6 | month="Jun", 7 | day="01", 8 | volume="24", 9 | number="2", 10 | pages="424--450", 11 | abstract="The use of computers and complex software is pervasive in archaeology, yet their role in the analytical pipeline is rarely exposed for other researchers to inspect or reuse. This limits the progress of archaeology because researchers cannot easily reproduce each other's work to verify or extend it. Four general principles of reproducible research that have emerged in other fields are presented. An archaeological case study is described that shows how each principle can be implemented using freely available software. The costs and benefits of implementing reproducible research are assessed. The primary benefit, of sharing data in particular, is increased impact via an increased number of citations. The primary cost is the additional time required to enhance reproducibility, although the exact amount is difficult to quantify.", 12 | issn="1573-7764", 13 | doi="10.1007/s10816-015-9272-9", 14 | url="https://doi.org/10.1007/s10816-015-9272-9" 15 | } 16 | -------------------------------------------------------------------------------- /CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (http:contributor-covenant.org), version 1.0.0, available at 25 | http://contributor-covenant.org/version/1/0/0/ 26 | -------------------------------------------------------------------------------- /analysis/templates/template.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "My title" 3 | author: 4 | - author 1 5 | - other author 6 | date: '`r Sys.Date()`' 7 | output: word_document 8 | abstract: "My abstract \n" 9 | --- 10 | 11 | ```{r setup, include=FALSE} 12 | knitr::opts_chunk$set(echo = FALSE) 13 | ``` 14 | 15 | # Heading 1 16 | 17 | ## Heading 2 18 | 19 | ### Heading 3 20 | 21 | #### Heading 4 22 | 23 | ##### Heading 5 - this is for the page break with MS Word 24 | 25 | In the MS Word document, the following modifications must be made in the 'Modify Style' menu: 26 | 27 | + Set the font color to ‘white’ (rather than ‘Automatic’). 28 | + Select the smallest font size (8 rather than 11). 29 | + Select ‘Page break before’ in the ‘Line and Page Breaks’ tab. 30 | + Set the line spacing to ‘Exactly’ and ‘1 pt’ in the ‘Indents and Spacing’ tab. 31 | 32 | After these tweaks, the ‘Heading 5’ style will no longer format a heading of level 5. Instead it will insert a very small and white (and, thus, invisible) line followed by a page break. 33 | 34 | Now knit this doc, and edit the styles in the resulting docx file. Then rename as 'template' and use this in the yml: 35 | 36 | ``` 37 | output: 38 | word_document: 39 | reference_docx: templates/template.docx 40 | ``` 41 | 42 | Don't forget line numbers for JAS! Headings are bold, underline, nothing. And Arial Narrow 10pt for tables. 43 | 44 | See here for more information: http://rmarkdown.rstudio.com/articles_docx.html 45 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We love pull requests from everyone. By participating in this project, you 4 | agree to abide by our [code of conduct](CONDUCT.md). 5 | 6 | ## Getting Started 7 | 8 | * Make sure you have a [GitHub account](https://github.com/signup/free). If you are not familar with git and GitHub, take a look at to get started. 9 | * [Submit a post for your issue](https://github.com/nevrome/rrtools.test/issues/), assuming one does not already exist. 10 | * Clearly describe your issue, including steps to reproduce when it is a bug, or some justification for a proposed improvement. 11 | * [Fork](https://github.com/nevrome/rrtools.test/#fork-destination-box) the repository on GitHub to make a copy of the repository on your account. Or use this line in your shell terminal: 12 | 13 | `git clone git@github.com:your-username/rrtools.test.git` 14 | 15 | ## Making changes 16 | 17 | * Edit the files, save often, and make commits of logical units, where each commit indicates one concept 18 | * Follow our [style guide](http://adv-r.had.co.nz/Style.html). 19 | * Make sure you write [good commit messages](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). 20 | * Make sure you have added the necessary tests for your code changes. 21 | * Run _all_ the tests using `devtools::check()` to assure nothing else was accidentally broken. 22 | * If you need help or unsure about anything, post an update to [your issue](https://github.com/nevrome/rrtools.test/issues/). 23 | 24 | ## Submitting your changes 25 | 26 | Push to your fork and [submit a pull request](https://github.com/nevrome/rrtools.test/compare/). 27 | 28 | At this point you're waiting on us. We like to at least comment on pull requests 29 | within a few days (and, typically, one business day). We may suggest 30 | some changes or improvements or alternatives. 31 | 32 | Some things you can do that will increase the chance that your pull request is accepted: 33 | 34 | * Engage in discussion on [your issue](https://github.com/nevrome/rrtools.test/issues/). 35 | * Be familiar with the backround literature cited in the [README](README.Rmd) 36 | * Write tests that pass. 37 | * Follow our [code style guide](http://adv-r.had.co.nz/Style.html). 38 | * Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /analysis/paper/paper.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Title Goes Here" 3 | author: 4 | - Myfirstname Mylastname: 5 | email: fl@oneplace.edu 6 | institute: [UofO] 7 | correspondence: true 8 | - Yourfirstname Yourlastname: 9 | email: fl@another.edu 10 | institute: [UofA] 11 | correspondence: false 12 | institute: 13 | - UofO: University of One Place 14 | - UofA: University of Another Place 15 | date: "`r format(Sys.time(), '%d %B, %Y')`" 16 | output: 17 | bookdown::word_document2: 18 | fig_caption: yes 19 | reference_docx: "../templates/template.docx" # Insert path for the DOCX file 20 | pandoc_args: 21 | - --lua-filter=../templates/scholarly-metadata.lua 22 | - --lua-filter=../templates/author-info-blocks.lua 23 | - --lua-filter=../templates/pagebreak.lua 24 | bibliography: references.bib 25 | csl: "../templates/journal-of-archaeological-science.csl" # Insert path for the bib-style 26 | abstract: | 27 | Text of abstract 28 | keywords: | 29 | keyword 1; keyword 2; keyword 3 30 | highlights: | 31 | These are the highlights. 32 | --- 33 | 34 | 35 | 36 | 37 | ```{r setup, echo = FALSE} 38 | knitr::opts_chunk$set( 39 | collapse = TRUE, 40 | warning = FALSE, 41 | message = FALSE, 42 | echo = FALSE, 43 | comment = "#>", 44 | fig.path = "../figures/", 45 | dpi = 300 46 | ) 47 | ``` 48 | 49 | # Introduction 50 | 51 | Here is a citation [@Marwick2017] 52 | 53 | # Background 54 | 55 | # Methods 56 | 57 | # Results 58 | 59 | ```{r get-data, eval = FALSE} 60 | # Note the path that we need to use to access our data files when rendering this document 61 | my_data <- read.csv(here::here('analysis/data/raw_data/my_csv_file.csv')) 62 | ``` 63 | 64 | ```{r demo-plot, fig.cap="A plot of random numbers"} 65 | plot(rnorm(10)) 66 | ``` 67 | 68 | Figure \@ref(fig:demo-plot) shows how we can have a caption and cross-reference for a plot 69 | 70 | ```{r demo-inline-code} 71 | x <- round(pi, 2) 72 | ``` 73 | 74 | Here is an example of inline code `r x` in the middle of a sentence. 75 | 76 | # Discussion 77 | 78 | # Conclusion 79 | 80 | # Acknowledgements 81 | 82 | 83 | \newpage 84 | 85 | # References 86 | 87 |
88 | 89 | \newpage 90 | 91 | ### Colophon 92 | 93 | This report was generated on `r Sys.time()` using the following computational environment and dependencies: 94 | 95 | ```{r colophon, cache = FALSE} 96 | # which R packages and versions? 97 | if ("devtools" %in% installed.packages()) devtools::session_info() 98 | ``` 99 | 100 | The current Git commit details are: 101 | 102 | ```{r} 103 | # what commit is this file at? 104 | if ("git2r" %in% installed.packages() & git2r::in_repository(path = ".")) git2r::repository(here::here()) 105 | ``` 106 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # rrtools.test 5 | 6 | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/nevrome/rrtools.test/master?urlpath=rstudio) 7 | 8 | This repository contains the data and code for our paper: 9 | 10 | > Authors, (YYYY). *Title of your paper goes here*. Name of journal/book 11 | > 12 | 13 | Our pre-print is online here: 14 | 15 | > Authors, (YYYY). *Title of your paper goes here*. Name of 16 | > journal/book, Accessed 05 Apr 2020. Online at 17 | > 18 | 19 | ### How to cite 20 | 21 | Please cite this compendium as: 22 | 23 | > Authors, (2020). *Compendium of R code and data for Title of your 24 | > paper goes here*. Accessed 05 Apr 2020. Online at 25 | > 26 | 27 | ## Contents 28 | 29 | The **analysis** directory contains: 30 | 31 | - [:file\_folder: paper](/analysis/paper): R Markdown source document 32 | for manuscript. Includes code to reproduce the figures and tables 33 | generated by the analysis. It also has a rendered version, 34 | `paper.docx`, suitable for reading (the code is replaced by figures 35 | and tables in this file) 36 | - [:file\_folder: data](/analysis/data): Data used in the analysis. 37 | - [:file\_folder: figures](/analysis/figures): Plots and other 38 | illustrations 39 | - [:file\_folder: 40 | supplementary-materials](/analysis/supplementary-materials): 41 | Supplementary materials including notes and other documents prepared 42 | and collected during the analysis. 43 | 44 | ## How to run in your broswer or download and run locally 45 | 46 | This research compendium has been developed using the statistical 47 | programming language R. To work with the compendium, you will need 48 | installed on your computer the [R 49 | software](https://cloud.r-project.org/) itself and optionally [RStudio 50 | Desktop](https://rstudio.com/products/rstudio/download/). 51 | 52 | The simplest way to explore the text, code and data is to click on 53 | [binder](https://mybinder.org/v2/gh/nevrome/rrtools.test/master?urlpath=rstudio) 54 | to open an instance of RStudio in your browser, which will have the 55 | compendium files ready to work with. Binder uses rocker-project.org 56 | Docker images to ensure a consistent and reproducible computational 57 | environment. These Docker images can also be used locally. 58 | 59 | You can download the compendium as a zip from from this URL: 60 | [master.zip](/archive/master.zip). After unzipping: - open the `.Rproj` 61 | file in RStudio - run `devtools::install()` to ensure you have the 62 | packages this analysis depends on (also listed in the 63 | [DESCRIPTION](/DESCRIPTION) file). - finally, open 64 | `analysis/paper/paper.Rmd` and knit to produce the `paper.docx`, or run 65 | `rmarkdown::render("analysis/paper/paper.Rmd")` in the R console 66 | 67 | ### Licenses 68 | 69 | **Text and figures :** 70 | [CC-BY-4.0](http://creativecommons.org/licenses/by/4.0/) 71 | 72 | **Code :** See the [DESCRIPTION](DESCRIPTION) file 73 | 74 | **Data :** [CC-0](http://creativecommons.org/publicdomain/zero/1.0/) 75 | attribution requested in reuse 76 | 77 | ### Contributions 78 | 79 | We welcome contributions from everyone. Before you get started, please 80 | see our [contributor guidelines](CONTRIBUTING.md). Please note that this 81 | project is released with a [Contributor Code of Conduct](CONDUCT.md). By 82 | participating in this project you agree to abide by its terms. 83 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, echo = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "README-" 12 | ) 13 | # Please put your title here to include it in the file below. 14 | Title <- "Title of your paper goes here" 15 | ``` 16 | 17 | # rrtools.test 18 | 19 | [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/nevrome/rrtools.test/master?urlpath=rstudio) 20 | 21 | This repository contains the data and code for our paper: 22 | 23 | > Authors, (YYYY). _`r Title`_. Name of journal/book 24 | 25 | Our pre-print is online here: 26 | 27 | > Authors, (YYYY). _`r Title`_. Name of journal/book, Accessed `r format(Sys.Date(), "%d %b %Y")`. Online at 28 | 29 | 30 | ### How to cite 31 | 32 | Please cite this compendium as: 33 | 34 | > Authors, (`r format(Sys.Date(), "%Y")`). _Compendium of R code and data for `r Title`_. Accessed `r format(Sys.Date(), "%d %b %Y")`. Online at 35 | 36 | ## Contents 37 | 38 | The **analysis** directory contains: 39 | 40 | - [:file\_folder: paper](/analysis/paper): R Markdown source document 41 | for manuscript. Includes code to reproduce the figures and tables 42 | generated by the analysis. It also has a rendered version, 43 | `paper.docx`, suitable for reading (the code is replaced by figures 44 | and tables in this file) 45 | - [:file\_folder: data](/analysis/data): Data used in the analysis. 46 | - [:file\_folder: figures](/analysis/figures): Plots and other 47 | illustrations 48 | - [:file\_folder: 49 | supplementary-materials](/analysis/supplementary-materials): 50 | Supplementary materials including notes and other documents 51 | prepared and collected during the analysis. 52 | 53 | ## How to run in your broswer or download and run locally 54 | 55 | This research compendium has been developed using the statistical programming 56 | language R. To work with the compendium, you will need 57 | installed on your computer the [R software](https://cloud.r-project.org/) 58 | itself and optionally [RStudio Desktop](https://rstudio.com/products/rstudio/download/). 59 | 60 | The simplest way to explore the text, code and data is to click on 61 | [binder](https://mybinder.org/v2/gh/nevrome/rrtools.test/master?urlpath=rstudio) 62 | to open an instance of RStudio in your browser, which will have the 63 | compendium files ready to work with. Binder uses rocker-project.org 64 | Docker images to ensure a consistent and reproducible computational 65 | environment. These Docker images can also be used locally. 66 | 67 | You can download the compendium as a zip from from this URL: 68 | [master.zip](/archive/master.zip). After unzipping: 69 | - open the `.Rproj` file in RStudio 70 | - run `devtools::install()` to ensure you have the packages this analysis depends on (also listed in the 71 | [DESCRIPTION](/DESCRIPTION) file). 72 | - finally, open `analysis/paper/paper.Rmd` and knit to produce the `paper.docx`, or run `rmarkdown::render("analysis/paper/paper.Rmd")` in the R console 73 | 74 | ### Licenses 75 | 76 | **Text and figures :** [CC-BY-4.0](http://creativecommons.org/licenses/by/4.0/) 77 | 78 | **Code :** See the [DESCRIPTION](DESCRIPTION) file 79 | 80 | **Data :** [CC-0](http://creativecommons.org/publicdomain/zero/1.0/) attribution requested in reuse 81 | 82 | ### Contributions 83 | 84 | We welcome contributions from everyone. Before you get started, please see our [contributor guidelines](CONTRIBUTING.md). Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms. 85 | 86 | -------------------------------------------------------------------------------- /analysis/templates/pagebreak.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | pagebreak – convert raw LaTeX page breaks to other formats 3 | 4 | Copyright © 2017-2019 Benct Philip Jonsson, Albert Krewinkel 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any 7 | purpose with or without fee is hereby granted, provided that the above 8 | copyright notice and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | ]] 18 | local stringify_orig = (require 'pandoc.utils').stringify 19 | 20 | local function stringify(x) 21 | return type(x) == 'string' and x or stringify_orig(x) 22 | end 23 | 24 | --- configs – these are populated in the Meta filter. 25 | local pagebreak = { 26 | epub = '

', 27 | html = '
', 28 | latex = '\\newpage{}', 29 | ooxml = '', 30 | odt = '' 31 | } 32 | 33 | local function pagebreaks_from_config (meta) 34 | local html_class = 35 | (meta.newpage_html_class and stringify(meta.newpage_html_class)) 36 | or os.getenv 'PANDOC_NEWPAGE_HTML_CLASS' 37 | if html_class and html_class ~= '' then 38 | pagebreak.html = string.format('
', html_class) 39 | end 40 | 41 | local odt_style = 42 | (meta.newpage_odt_style and stringify(meta.newpage_odt_style)) 43 | or os.getenv 'PANDOC_NEWPAGE_ODT_STYLE' 44 | if odt_style and odt_style ~= '' then 45 | pagebreak.odt = string.format('', odt_style) 46 | end 47 | end 48 | 49 | --- Return a block element causing a page break in the given format. 50 | local function newpage(format) 51 | if format == 'docx' then 52 | return pandoc.RawBlock('openxml', pagebreak.ooxml) 53 | elseif format:match 'latex' then 54 | return pandoc.RawBlock('tex', pagebreak.latex) 55 | elseif format:match 'odt' then 56 | return pandoc.RawBlock('opendocument', pagebreak.odt) 57 | elseif format:match 'html.*' then 58 | return pandoc.RawBlock('html', pagebreak.html) 59 | elseif format:match 'epub' then 60 | return pandoc.RawBlock('html', pagebreak.epub) 61 | else 62 | -- fall back to insert a form feed character 63 | return pandoc.Para{pandoc.Str '\f'} 64 | end 65 | end 66 | 67 | local function is_newpage_command(command) 68 | return command:match '^\\newpage%{?%}?$' 69 | or command:match '^\\pagebreak%{?%}?$' 70 | end 71 | 72 | -- Filter function called on each RawBlock element. 73 | function RawBlock (el) 74 | -- Don't do anything if the output is TeX 75 | if FORMAT:match 'tex$' then 76 | return nil 77 | end 78 | -- check that the block is TeX or LaTeX and contains only 79 | -- \newpage or \pagebreak. 80 | if el.format:match 'tex' and is_newpage_command(el.text) then 81 | -- use format-specific pagebreak marker. FORMAT is set by pandoc to 82 | -- the targeted output format. 83 | return newpage(FORMAT) 84 | end 85 | -- otherwise, leave the block unchanged 86 | return nil 87 | end 88 | 89 | -- Turning paragraphs which contain nothing but a form feed 90 | -- characters into line breaks. 91 | function Para (el) 92 | if #el.content == 1 and el.content[1].text == '\f' then 93 | return newpage(FORMAT) 94 | end 95 | end 96 | 97 | return { 98 | {Meta = pagebreaks_from_config}, 99 | {RawBlock = RawBlock, Para = Para} 100 | } 101 | -------------------------------------------------------------------------------- /analysis/templates/scholarly-metadata.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | ScholarlyMeta – normalize author/affiliation meta variables 3 | 4 | Copyright (c) 2017-2019 Albert Krewinkel, Robert Winkler 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any purpose 7 | with or without fee is hereby granted, provided that the above copyright notice 8 | and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 11 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 12 | FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 13 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 14 | OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 16 | THIS SOFTWARE. 17 | ]] 18 | local List = require 'pandoc.List' 19 | 20 | -- Split a string at commas. 21 | local function comma_separated_values(str) 22 | local acc = List:new{} 23 | for substr in str:gmatch('([^,]*)') do 24 | acc[#acc + 1] = substr:gsub('^%s*', ''):gsub('%s*$', '') -- trim 25 | end 26 | return acc 27 | end 28 | 29 | --- Ensure the return value is a list. 30 | local function ensure_list (val) 31 | if type(val) ~= 'table' then 32 | -- create singleton list (or empty list if val == nil). 33 | return List:new{val} 34 | elseif val.t == 'MetaInlines' then 35 | -- check if this is really a comma-separated list 36 | local csv = comma_separated_values(pandoc.utils.stringify(val)) 37 | if #csv >= 2 then 38 | return csv 39 | end 40 | return List:new{val} 41 | elseif val.t == 'MetaList' then 42 | return List:new(val) 43 | else 44 | -- MetaBlocks or MetaMap, use as a singleton 45 | return List:new{val} 46 | end 47 | end 48 | 49 | --- Returns a function which checks whether an object has the given ID. 50 | local function has_id (id) 51 | return function(x) return x.id == id end 52 | end 53 | 54 | --- Copy all key-value pairs of the first table into the second iff there is no 55 | -- such key yet in the second table. 56 | -- @returns the second argument 57 | function add_missing_entries(a, b) 58 | for k, v in pairs(a) do 59 | b[k] = b[k] or v 60 | end 61 | return b 62 | end 63 | 64 | --- Create an object with a name. The name is either taken directly from the 65 | -- `name` field, or from the *only* field name (i.e., key) if the object is a 66 | -- dictionary with just one entry. If neither exists, the name is left unset 67 | -- (`nil`). 68 | function to_named_object (obj) 69 | local named = {} 70 | if type(obj) ~= 'table' then 71 | -- if the object isn't a table, just use its value as a name. 72 | named.name = pandoc.MetaInlines{pandoc.Str(tostring(obj))} 73 | named.id = tostring(obj) 74 | elseif obj.t == 'MetaInlines' then 75 | -- Treat inlines as the name 76 | named.name = obj 77 | named.id = pandoc.utils.stringify(obj) 78 | elseif obj.name ~= nil then 79 | -- object has name attribute → just create a copy of the object 80 | add_missing_entries(obj, named) 81 | named.id = pandoc.utils.stringify(named.id or named.name) 82 | elseif next(obj) and next(obj, next(obj)) == nil then 83 | -- the entry's key is taken as the name, the value contains the 84 | -- attributes. 85 | key, attribs = next(obj) 86 | if type(attribs) == "string" or attribs.t == 'MetaInlines' then 87 | named.name = attribs 88 | else 89 | add_missing_entries(attribs, named) 90 | named.name = named.name or pandoc.MetaInlines{pandoc.Str(tostring(key))} 91 | end 92 | named.id = named.id and pandoc.utils.stringify(named.id) or key 93 | else 94 | -- this is not a named object adhering to the usual conventions. 95 | error('not a named object: ' .. tostring(obj)) 96 | end 97 | return named 98 | end 99 | 100 | --- Resolve institute placeholders to full named objects 101 | local function resolve_institutes (institute, known_institutes) 102 | local unresolved_institutes 103 | if institute == nil then 104 | unresolved_institutes = {} 105 | elseif type(institute) == "string" or type(institute) == "number" then 106 | unresolved_institutes = {institute} 107 | else 108 | unresolved_institutes = institute 109 | end 110 | 111 | local result = List:new{} 112 | for i, inst in ipairs(unresolved_institutes) do 113 | result[i] = 114 | known_institutes[tonumber(inst)] or 115 | known_institutes:find_if(has_id(pandoc.utils.stringify(inst))) or 116 | to_named_object(inst) 117 | end 118 | return result 119 | end 120 | 121 | --- Insert a named object into a list; if an object of the same name exists 122 | -- already, add all properties only present in the new object to the existing 123 | -- item. 124 | function merge_on_id (list, namedObj) 125 | local elem, idx = list:find_if(has_id(namedObj.id)) 126 | local res = elem and add_missing_entries(namedObj, elem) or namedObj 127 | local obj_idx = idx or (#list + 1) 128 | -- return res, obj_idx 129 | list[obj_idx] = res 130 | return res, #list 131 | end 132 | 133 | --- Flatten a list of lists. 134 | local function flatten (lists) 135 | local result = List:new{} 136 | for _, lst in ipairs(lists) do 137 | result:extend(lst) 138 | end 139 | return result 140 | end 141 | 142 | --- Canonicalize authors and institutes 143 | local function canonicalize(raw_author, raw_institute) 144 | local institutes = ensure_list(raw_institute):map(to_named_object) 145 | local authors = ensure_list(raw_author):map(to_named_object) 146 | 147 | for _, author in ipairs(authors) do 148 | author.institute = resolve_institutes( 149 | ensure_list(author.institute), 150 | institutes 151 | ) 152 | end 153 | 154 | -- Merge institutes defined in author objects with those defined in the 155 | -- top-level list. 156 | local author_insts = flatten(authors:map(function(x) return x.institute end)) 157 | for _, inst in ipairs(author_insts) do 158 | merge_on_id(institutes, inst) 159 | end 160 | 161 | -- replace institutes with their indices 162 | local to_index = function (inst) 163 | return tostring(select(2, institutes:find_if(has_id(inst.id)))) 164 | end 165 | for _, author in ipairs(authors) do 166 | author.institute = pandoc.MetaList(author.institute:map(to_index)) 167 | end 168 | 169 | return authors, institutes 170 | end 171 | 172 | 173 | return { 174 | { 175 | Meta = function(meta) 176 | meta.author, meta.institute = canonicalize(meta.author, meta.institute) 177 | return meta 178 | end 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /analysis/templates/author-info-blocks.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | affiliation-blocks – generate title components 3 | 4 | Copyright © 2017–2019 Albert Krewinkel 5 | 6 | Permission to use, copy, modify, and/or distribute this software for any purpose 7 | with or without fee is hereby granted, provided that the above copyright notice 8 | and this permission notice appear in all copies. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 11 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 12 | FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 13 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 14 | OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 16 | THIS SOFTWARE. 17 | ]] 18 | local List = require 'pandoc.List' 19 | local utils = require 'pandoc.utils' 20 | local stringify = utils.stringify 21 | 22 | local default_marks 23 | local default_marks = { 24 | corresponding_author = FORMAT == 'latex' 25 | and {pandoc.RawInline('latex', '*')} 26 | or {pandoc.Str '✉'}, 27 | equal_contributor = FORMAT == 'latex' 28 | and {pandoc.RawInline('latex', '$\\dagger{}$')} 29 | or {pandoc.Str '*'}, 30 | } 31 | 32 | local function intercalate(lists, elem) 33 | local result = List:new{} 34 | for i = 1, (#lists - 1) do 35 | result:extend(lists[i]) 36 | result:extend(elem) 37 | end 38 | if #lists > 0 then 39 | result:extend(lists[#lists]) 40 | end 41 | return result 42 | end 43 | 44 | --- Check whether the given author is a corresponding author 45 | local function is_corresponding_author(author) 46 | return author.correspondence and author.email 47 | end 48 | 49 | --- Create inlines for a single author (includes all author notes) 50 | local function author_inline_generator (get_mark) 51 | return function (author) 52 | local author_marks = List:new{} 53 | if author.equal_contributor then 54 | author_marks[#author_marks + 1] = get_mark 'equal_contributor' 55 | end 56 | local idx_str 57 | for _, idx in ipairs(author.institute) do 58 | if type(idx) ~= 'table' then 59 | idx_str = tostring(idx) 60 | else 61 | idx_str = stringify(idx) 62 | end 63 | author_marks[#author_marks + 1] = {pandoc.Str(idx_str)} 64 | end 65 | if is_corresponding_author(author) then 66 | author_marks[#author_marks + 1] = get_mark 'corresponding_author' 67 | end 68 | local res = List.clone(author.name) 69 | res[#res + 1] = pandoc.Superscript(intercalate(author_marks, {pandoc.Str ','})) 70 | return res 71 | end 72 | end 73 | 74 | local function is_equal_contributor (author) 75 | return author.equal_contributor 76 | end 77 | 78 | --- Create equal contributors note. 79 | local function create_equal_contributors_block(authors, mark) 80 | local has_equal_contribs = List:new(authors):find_if(is_equal_contributor) 81 | if not has_equal_contribs then 82 | return nil 83 | end 84 | local contributors = { 85 | pandoc.Superscript(mark'equal_contributor'), 86 | pandoc.Space(), 87 | pandoc.Str 'These authors contributed equally to this work.' 88 | } 89 | return List:new{pandoc.Para(contributors)} 90 | end 91 | 92 | --- Generate a block list all affiliations, marked with arabic numbers. 93 | local function create_affiliations_blocks(affiliations) 94 | local affil_lines = List:new(affiliations):map( 95 | function (affil, i) 96 | local num_inlines = List:new{ 97 | pandoc.Superscript{pandoc.Str(tostring(i))}, 98 | pandoc.Space() 99 | } 100 | return num_inlines .. affil.name 101 | end 102 | ) 103 | return {pandoc.Para(intercalate(affil_lines, {pandoc.LineBreak()}))} 104 | end 105 | 106 | --- Generate a block element containing the correspondence information 107 | local function create_correspondence_blocks(authors, mark) 108 | local corresponding_authors = List:new{} 109 | for _, author in ipairs(authors) do 110 | if is_corresponding_author(author) then 111 | local mailto = 'mailto:' .. pandoc.utils.stringify(author.email) 112 | local author_with_mail = List:new( 113 | author.name .. List:new{pandoc.Space(), pandoc.Str '<'} .. 114 | author.email .. List:new{pandoc.Str '>'} 115 | ) 116 | local link = pandoc.Link(author_with_mail, mailto) 117 | table.insert(corresponding_authors, {link}) 118 | end 119 | end 120 | if #corresponding_authors == 0 then 121 | return nil 122 | end 123 | local correspondence = List:new{ 124 | pandoc.Superscript(mark'corresponding_author'), 125 | pandoc.Space(), 126 | pandoc.Str'Correspondence:', 127 | pandoc.Space() 128 | } 129 | local sep = List:new{pandoc.Str',', pandoc.Space()} 130 | return { 131 | pandoc.Para(correspondence .. intercalate(corresponding_authors, sep)) 132 | } 133 | end 134 | 135 | --- Generate a list of inlines containing all authors. 136 | local function create_authors_inlines(authors, mark) 137 | local inlines_generator = author_inline_generator(mark) 138 | local inlines = List:new(authors):map(inlines_generator) 139 | local and_str = List:new{pandoc.Space(), pandoc.Str'and', pandoc.Space()} 140 | 141 | local last_author = inlines[#inlines] 142 | inlines[#inlines] = nil 143 | local result = intercalate(inlines, {pandoc.Str ',', pandoc.Space()}) 144 | if #authors > 1 then 145 | result:extend(List:new{pandoc.Str ","} .. and_str) 146 | end 147 | result:extend(last_author) 148 | return result 149 | end 150 | 151 | return { 152 | { 153 | Pandoc = function (doc) 154 | local meta = doc.meta 155 | local body = List:new{} 156 | 157 | local mark = function (mark_name) return default_marks[mark_name] end 158 | 159 | body:extend(create_equal_contributors_block(doc.meta.author, mark) or {}) 160 | body:extend(create_affiliations_blocks(doc.meta.institute) or {}) 161 | body:extend(create_correspondence_blocks(doc.meta.author, mark) or {}) 162 | body:extend(doc.blocks) 163 | 164 | -- Overwrite authors with formatted values. We use a single, formatted 165 | -- string for most formats. LaTeX output, however, looks nicer if we 166 | -- provide a authors as a list. 167 | meta.author = FORMAT:match 'latex' 168 | and pandoc.MetaList(doc.meta.author):map(author_inline_generator(mark)) 169 | or pandoc.MetaInlines(create_authors_inlines(doc.meta.author, mark)) 170 | -- Institute info is now baked into the affiliations block. 171 | meta.institute = nil 172 | 173 | return pandoc.Pandoc(body, meta) 174 | end 175 | } 176 | } 177 | --------------------------------------------------------------------------------