From e1de4c3cb3f5dc624c9074dee49f4d61d1367a57 Mon Sep 17 00:00:00 2001 From: RLumSK Date: Tue, 14 Apr 2020 21:02:47 +0200 Subject: [PATCH 01/36] Address #287 + Added automated file renaming of the bib-file + Added replacment of the corresponding bibliography entry in the Rmd-file + Added R script file production with the name of the file as the Rmd-file (as suggested in the issues description) + Added NEWS + Update DESCRIPTION --- DESCRIPTION | 5 +++-- NEWS.md | 2 +- R/rjournal_article.R | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6a3d42234..233d24aaa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,7 +38,8 @@ Authors@R: c( person("Noam", "Ross", role = c("aut", "cph"), email = "noam.ross@gmail.com", comment = c(ORCID = "0000-0002-2136-0000")), person("Robrecht", "Cannoodt", role = c("aut", "cph"), email = "rcannood@gmail.com", comment = c(ORCID = "0000-0003-3641-729X", github = "rcannood")), person("Duncan", "Luguern", role = c("aut"), email = "duncan.luguern@gmail.com"), - person("David M.", "Kaplan", role = c("aut", "ctb"), email = "dmkaplan2000@gmail.com", comment = c(ORCID = "0000-0001-6087-359X", github = "dmkaplan2000")) + person("David M.", "Kaplan", role = c("aut", "ctb"), email = "dmkaplan2000@gmail.com", comment = c(ORCID = "0000-0001-6087-359X", github = "dmkaplan2000")), + person("Sebastian", "Kreutzer", role = c("aut"), email = "sebastian.kreutzer@aber.ac.uk", comment = c(ORCID = "0000-0002-0734-2199")) ) Description: A suite of custom R Markdown formats and templates for authoring journal articles and conference submissions. @@ -47,6 +48,6 @@ Imports: utils, rmarkdown, knitr, yaml, tinytex (>= 0.19), xfun SystemRequirements: GNU make URL: https://github.com/rstudio/rticles BugReports: https://github.com/rstudio/rticles/issues -RoxygenNote: 7.0.2 +RoxygenNote: 7.1.0 Suggests: testit, bookdown, xtable Encoding: UTF-8 diff --git a/NEWS.md b/NEWS.md index a3d8f0e71..a5fbddc73 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ rticles 0.15 --------------------------------------------------------------------- - +- Added for `rjournal_article()` (1) automated file renaming to better match the author's guidelines, (2) an R script file with for the reproduction of examples rticles 0.14 --------------------------------------------------------------------- diff --git a/R/rjournal_article.R b/R/rjournal_article.R index 9e4fe8f8a..a9f8304b7 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -6,6 +6,30 @@ #' @export rjournal_article <- function(..., citation_package = 'natbib') { + ## make sure that all files are correctly named according to the R journal + ## requirements https://journal.r-project.org/submissions.html + + ## get name of Bib-file and Rmd-file + Rmd_file_name <- list.files( + path = ".", pattern = ".Rmd", include.dirs = FALSE)[1] + bib_file_name <- list.files( + path = ".", pattern = ".bib", include.dirs = FALSE)[1] + + ## correct bibliography entry in Rmd-file + Rmd_file_text <- readLines(Rmd_file_name) + pat <- regexpr("(?<=\\\\bibliography{).+[^}]", Rmd_file_text, perl = TRUE) + regmatches(Rmd_file_text, pat) <- xfun::sans_ext(Rmd_file_name) + writeLines(text = Rmd_file_text, con = Rmd_file_name) + + ## correct bib-filename to match the name of the Rmd-file + file.rename(from = bib_file_name, to = paste0(xfun::sans_ext(Rmd_file_name), ".bib")) + + ## create R file with executable R code as requested + knitr::purl(Rmd_file_name, documentation = 1) + + ##remove objects + suppressWarnings(rm(Rmd_file_name, Rmd_file_text, bib_file_name)) + rmarkdown::pandoc_available('2.2', TRUE) base <- pdf_document_format( From c5ba9e79e32d6283d316447b01b42622f6015f58 Mon Sep 17 00:00:00 2001 From: RLumSK Date: Thu, 2 Apr 2020 12:23:06 +0200 Subject: [PATCH 02/36] Modify rjournal_article template: + Now the YAML header supports more than one affiliation per author + If the author has only one affiliation, nothing has changed --- .../rjournal_article/resources/template.tex | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/inst/rmarkdown/templates/rjournal_article/resources/template.tex b/inst/rmarkdown/templates/rjournal_article/resources/template.tex index 2ffc82a74..178dba3ff 100644 --- a/inst/rmarkdown/templates/rjournal_article/resources/template.tex +++ b/inst/rmarkdown/templates/rjournal_article/resources/template.tex @@ -19,9 +19,17 @@ $for(author)$ \address{% $author.name$\\ -$author.affiliation$\\ -$for(author.address)$$author.address$$sep$\\ $endfor$\\ +$for(author.affiliation/pairs)$ + $if(it.value)$ + $for(it.value.name)$$it.value.name$\\$endfor$% + $for(it.value.address)$$it.value.address$$sep$ \\$endfor$% + $for(it.value.email)$\\$it.value.email$\\\\$endfor$% + $else$ + $author.affiliation$\\ + $endif$ +$endfor$ +$for(author.address)$$author.address$$sep$ \\$endfor$% } -$if(author.email)$$author.email$$endif$ +$if(author.email)$\\$author.email$$endif$ $endfor$ From 12f34ce198b1e4fd43dd3c8caddebb62ae88f1e3 Mon Sep 17 00:00:00 2001 From: RLumSK Date: Thu, 2 Apr 2020 12:23:06 +0200 Subject: [PATCH 03/36] Modify rjournal_article template: + Now the YAML header supports more than one affiliation per author + If the author has only one affiliation, nothing has changed + Update corresponding skeleton.Rmd to have example for multiple affiliations + Update DESCRIPTION + Update NEWS --- NEWS.md | 1 + .../rjournal_article/resources/RJwrapper.log | 58 +++++++++++++++++++ .../rjournal_article/skeleton/skeleton.Rmd | 15 +++-- 3 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 inst/rmarkdown/templates/rjournal_article/resources/RJwrapper.log diff --git a/NEWS.md b/NEWS.md index a5fbddc73..0143f49ac 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ rticles 0.15 --------------------------------------------------------------------- +- Added multi-affiliation support to `rjournal_article()`. - Added for `rjournal_article()` (1) automated file renaming to better match the author's guidelines, (2) an R script file with for the reproduction of examples rticles 0.14 diff --git a/inst/rmarkdown/templates/rjournal_article/resources/RJwrapper.log b/inst/rmarkdown/templates/rjournal_article/resources/RJwrapper.log new file mode 100644 index 000000000..cc116ff24 --- /dev/null +++ b/inst/rmarkdown/templates/rjournal_article/resources/RJwrapper.log @@ -0,0 +1,58 @@ +This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdflatex 2020.4.2) 14 APR 2020 11:25 +entering extended mode + restricted \write18 enabled. + %&-line parsing enabled. +**RJwrapper.tex +(./RJwrapper.tex +LaTeX2e <2020-02-02> patch level 5 +L3 programming layer <2020-02-25> +(/Users/kreutzer/Library/TinyTeX/texmf-dist/tex/latex/base/report.cls +Document Class: report 2019/12/20 v1.4l Standard LaTeX document class +(/Users/kreutzer/Library/TinyTeX/texmf-dist/tex/latex/base/size10.clo +File: size10.clo 2019/12/20 v1.4l Standard LaTeX file (size option) +) +\c@part=\count167 +\c@chapter=\count168 +\c@section=\count169 +\c@subsection=\count170 +\c@subsubsection=\count171 +\c@paragraph=\count172 +\c@subparagraph=\count173 +\c@figure=\count174 +\c@table=\count175 +\abovecaptionskip=\skip47 +\belowcaptionskip=\skip48 +\bibindent=\dimen134 +) +(/Users/kreutzer/Library/TinyTeX/texmf-dist/tex/latex/base/inputenc.sty +Package: inputenc 2018/08/11 v1.3c Input encoding file +\inpenc@prehook=\toks15 +\inpenc@posthook=\toks16 +) +(/Users/kreutzer/Library/TinyTeX/texmf-dist/tex/latex/base/fontenc.sty +Package: fontenc 2020/02/11 v2.0o Standard LaTeX package +) + +! LaTeX Error: File `RJournal.sty' not found. + +Type X to quit or to proceed, +or enter new name. (Default extension: sty) + +Enter file name: +! Emergency stop. + + +l.5 \usepackage + {amsmath,amssymb,array}^^M +*** (cannot \read from terminal in nonstop modes) + + +Here is how much of TeX's memory you used: + 470 strings out of 482918 + 4658 string characters out of 5958526 + 232890 words of memory out of 5000000 + 15823 multiletter control sequences out of 15000+600000 + 533101 words of font info for 25 fonts, out of 8000000 for 9000 + 14 hyphenation exceptions out of 8191 + 25i,0n,20p,155b,38s stack positions out of 5000i,500n,10000p,200000b,80000s +! ==> Fatal error occurred, no output PDF file produced! diff --git a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd index f26428e4a..be81df623 100644 --- a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd @@ -8,11 +8,16 @@ author: - line 2 email: author1@work - name: Author Two - affiliation: Affiliation - address: - - line 1 - - line 2 - email: author2@work + affiliation: + - name: Affiliation 1 + - address: + - line 1 affiliation 1 + - line 2 affiliation 1 + - email: author2@work + - name: Affiliation 2 + - address: + - line 1 affiliation 2 + - line 2 affiliation 2 abstract: > An abstract of less than 150 words. preamble: | From e0c42e290846097968f93b59e7cb9640e078d141 Mon Sep 17 00:00:00 2001 From: RLumSK Date: Tue, 14 Apr 2020 11:58:23 +0200 Subject: [PATCH 04/36] Make template more consistent and add support orcid and url --- .../templates/rjournal_article/resources/template.tex | 11 ++++++----- .../templates/rjournal_article/skeleton/skeleton.Rmd | 6 +++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/inst/rmarkdown/templates/rjournal_article/resources/template.tex b/inst/rmarkdown/templates/rjournal_article/resources/template.tex index 178dba3ff..0d023bb11 100644 --- a/inst/rmarkdown/templates/rjournal_article/resources/template.tex +++ b/inst/rmarkdown/templates/rjournal_article/resources/template.tex @@ -18,18 +18,19 @@ $for(author)$ \address{% -$author.name$\\ +$author.name$ $for(author.affiliation/pairs)$ $if(it.value)$ - $for(it.value.name)$$it.value.name$\\$endfor$% - $for(it.value.address)$$it.value.address$$sep$ \\$endfor$% - $for(it.value.email)$\\$it.value.email$\\\\$endfor$% + $for(it.value.name)$\\$it.value.name$$endfor$% + $for(it.value.address)$$it.value.address$$sep$ \\$endfor$\\% $else$ - $author.affiliation$\\ + \\$author.affiliation$\\ $endif$ $endfor$ $for(author.address)$$author.address$$sep$ \\$endfor$% } +$if(author.url)$\\$author.url$$endif$% +$if(author.orcid)$\\\textit{orcid: \href{https://orcid.org/$author.orcid$}{$author.orcid$}}$endif$% $if(author.email)$\\$author.email$$endif$ $endfor$ diff --git a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd index be81df623..f9aa6f23e 100644 --- a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd @@ -6,14 +6,18 @@ author: address: - line 1 - line 2 + url: https://journal.r-project.org + orcid: 0000-0002-9079-593X email: author1@work - name: Author Two + url: https://journal.r-project.org + email: author2@work + orcid: 0000-0002-9079-593X affiliation: - name: Affiliation 1 - address: - line 1 affiliation 1 - line 2 affiliation 1 - - email: author2@work - name: Affiliation 2 - address: - line 1 affiliation 2 From 1a4940bfbc8c6e27cc0274991c552d3135b7dd4d Mon Sep 17 00:00:00 2001 From: RLumSK Date: Tue, 14 Apr 2020 21:33:41 +0200 Subject: [PATCH 05/36] Remove RJwrapper.log from last commit --- .../rjournal_article/resources/RJwrapper.log | 58 ------------------- 1 file changed, 58 deletions(-) delete mode 100644 inst/rmarkdown/templates/rjournal_article/resources/RJwrapper.log diff --git a/inst/rmarkdown/templates/rjournal_article/resources/RJwrapper.log b/inst/rmarkdown/templates/rjournal_article/resources/RJwrapper.log deleted file mode 100644 index cc116ff24..000000000 --- a/inst/rmarkdown/templates/rjournal_article/resources/RJwrapper.log +++ /dev/null @@ -1,58 +0,0 @@ -This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdflatex 2020.4.2) 14 APR 2020 11:25 -entering extended mode - restricted \write18 enabled. - %&-line parsing enabled. -**RJwrapper.tex -(./RJwrapper.tex -LaTeX2e <2020-02-02> patch level 5 -L3 programming layer <2020-02-25> -(/Users/kreutzer/Library/TinyTeX/texmf-dist/tex/latex/base/report.cls -Document Class: report 2019/12/20 v1.4l Standard LaTeX document class -(/Users/kreutzer/Library/TinyTeX/texmf-dist/tex/latex/base/size10.clo -File: size10.clo 2019/12/20 v1.4l Standard LaTeX file (size option) -) -\c@part=\count167 -\c@chapter=\count168 -\c@section=\count169 -\c@subsection=\count170 -\c@subsubsection=\count171 -\c@paragraph=\count172 -\c@subparagraph=\count173 -\c@figure=\count174 -\c@table=\count175 -\abovecaptionskip=\skip47 -\belowcaptionskip=\skip48 -\bibindent=\dimen134 -) -(/Users/kreutzer/Library/TinyTeX/texmf-dist/tex/latex/base/inputenc.sty -Package: inputenc 2018/08/11 v1.3c Input encoding file -\inpenc@prehook=\toks15 -\inpenc@posthook=\toks16 -) -(/Users/kreutzer/Library/TinyTeX/texmf-dist/tex/latex/base/fontenc.sty -Package: fontenc 2020/02/11 v2.0o Standard LaTeX package -) - -! LaTeX Error: File `RJournal.sty' not found. - -Type X to quit or to proceed, -or enter new name. (Default extension: sty) - -Enter file name: -! Emergency stop. - - -l.5 \usepackage - {amsmath,amssymb,array}^^M -*** (cannot \read from terminal in nonstop modes) - - -Here is how much of TeX's memory you used: - 470 strings out of 482918 - 4658 string characters out of 5958526 - 232890 words of memory out of 5000000 - 15823 multiletter control sequences out of 15000+600000 - 533101 words of font info for 25 fonts, out of 8000000 for 9000 - 14 hyphenation exceptions out of 8191 - 25i,0n,20p,155b,38s stack positions out of 5000i,500n,10000p,200000b,80000s -! ==> Fatal error occurred, no output PDF file produced! From cee64e67778633f935e9c27b40e285a4137351e7 Mon Sep 17 00:00:00 2001 From: RLumSK Date: Thu, 30 Apr 2020 13:01:07 +0200 Subject: [PATCH 06/36] The orcid was not typed ORCiD as the RJournal want to have it. --- .../rmarkdown/templates/rjournal_article/resources/template.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/rjournal_article/resources/template.tex b/inst/rmarkdown/templates/rjournal_article/resources/template.tex index 0d023bb11..8871b5044 100644 --- a/inst/rmarkdown/templates/rjournal_article/resources/template.tex +++ b/inst/rmarkdown/templates/rjournal_article/resources/template.tex @@ -30,7 +30,7 @@ $for(author.address)$$author.address$$sep$ \\$endfor$% } $if(author.url)$\\$author.url$$endif$% -$if(author.orcid)$\\\textit{orcid: \href{https://orcid.org/$author.orcid$}{$author.orcid$}}$endif$% +$if(author.orcid)$\\\textit{ORCiD: \href{https://orcid.org/$author.orcid$}{$author.orcid$}}$endif$% $if(author.email)$\\$author.email$$endif$ $endfor$ From f53c84dc9c3e571f52d2e18c6d0639d415a277d7 Mon Sep 17 00:00:00 2001 From: RLumSK Date: Sun, 9 Aug 2020 19:13:04 +0200 Subject: [PATCH 07/36] Include all address fields with the address braces as requested by the template --- .../rmarkdown/templates/rjournal_article/resources/template.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/rjournal_article/resources/template.tex b/inst/rmarkdown/templates/rjournal_article/resources/template.tex index 8871b5044..07b7c026a 100644 --- a/inst/rmarkdown/templates/rjournal_article/resources/template.tex +++ b/inst/rmarkdown/templates/rjournal_article/resources/template.tex @@ -28,9 +28,9 @@ $endif$ $endfor$ $for(author.address)$$author.address$$sep$ \\$endfor$% -} $if(author.url)$\\$author.url$$endif$% $if(author.orcid)$\\\textit{ORCiD: \href{https://orcid.org/$author.orcid$}{$author.orcid$}}$endif$% $if(author.email)$\\$author.email$$endif$ +} $endfor$ From 46889515fe193545a54e8752106f845d84345a76 Mon Sep 17 00:00:00 2001 From: RLumSK Date: Mon, 10 Aug 2020 12:51:34 +0200 Subject: [PATCH 08/36] #286 Update authors field to support two affiliations without using pipes not yet available in RStudio due to an older pandoc verison. The commit includes: + Updated template.tex as suggested by @cderv + Updated rjournal_article.R with more details in the documentation + Updated Rd-file --- R/rjournal_article.R | 25 +++++++++++++++++-- .../rjournal_article/resources/template.tex | 19 ++++++-------- man/rjournal_article.Rd | 17 +++++++++++++ 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index a9f8304b7..869fef3e5 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -1,8 +1,29 @@ -#' R Journal format. +#' @title R Journal format. #' -#' Format for creating R Journal articles. Adapted from +#' @description Format for creating R Journal articles. Adapted from #' \url{https://journal.r-project.org/submissions.html}. +#' +#' @details +#' +#' **The `author` field in the YAML-header** +#' +#' \tabular{lll}{ +#' FIELD \tab TYPE \tab DESCRIPTION\cr +#' `name` \tab *required* \tab name and surname of the author\cr +#' `affiliation` \tab *required* \tab name of the author's affiliation\cr +#' `address` \tab *required* \tab at least one address line for the affiliation\cr +#' `url` \tab *optional* \tab an additional url for the author or the main affiliation\cr +#' `orcid` \tab *optional* \tab the authors ORCID if available\cr +#' `email` \tab *required* \tab the author's e-mail address\cr +#' `affiliation2` \tab *optional* \tab name of the author's 2nd affiliation\cr +#' `address2` \tab *optional* \tab address lines belonging to the author's 2nd affiliation +#' } +#' +#' *Please note: Only one `url`, `orcid` and `email` can be provided per author.* +#' #' @param ...,citation_package Arguments to \code{rmarkdown::pdf_document}. +#' +#' @md #' @export rjournal_article <- function(..., citation_package = 'natbib') { diff --git a/inst/rmarkdown/templates/rjournal_article/resources/template.tex b/inst/rmarkdown/templates/rjournal_article/resources/template.tex index 07b7c026a..1267c918b 100644 --- a/inst/rmarkdown/templates/rjournal_article/resources/template.tex +++ b/inst/rmarkdown/templates/rjournal_article/resources/template.tex @@ -18,17 +18,14 @@ $for(author)$ \address{% -$author.name$ -$for(author.affiliation/pairs)$ - $if(it.value)$ - $for(it.value.name)$\\$it.value.name$$endfor$% - $for(it.value.address)$$it.value.address$$sep$ \\$endfor$\\% - $else$ - \\$author.affiliation$\\ - $endif$ -$endfor$ -$for(author.address)$$author.address$$sep$ \\$endfor$% -$if(author.url)$\\$author.url$$endif$% +$author.name$\\ +$author.affiliation$\\% +$for(author.address)$$author.address$$sep$\\ $endfor$\\ +$if(author.affiliation2)$ +$author.affiliation2$\\% +$for(author.address2)$$author.address2$$sep$\\ $endfor$\\ +$endif$% +$if(author.url)$$author.url$$endif$% $if(author.orcid)$\\\textit{ORCiD: \href{https://orcid.org/$author.orcid$}{$author.orcid$}}$endif$% $if(author.email)$\\$author.email$$endif$ } diff --git a/man/rjournal_article.Rd b/man/rjournal_article.Rd index 2ceafd8f2..dc008cbea 100644 --- a/man/rjournal_article.Rd +++ b/man/rjournal_article.Rd @@ -13,3 +13,20 @@ rjournal_article(..., citation_package = "natbib") Format for creating R Journal articles. Adapted from \url{https://journal.r-project.org/submissions.html}. } +\details{ +\strong{The \code{author} field in the YAML-header} + +\tabular{lll}{ +FIELD \tab TYPE \tab DESCRIPTION\cr +\code{name} \tab \emph{required} \tab name and surname of the author\cr +\code{affiliation} \tab \emph{required} \tab name of the author's affiliation\cr +\code{address} \tab \emph{required} \tab at least one address line for the affiliation\cr +\code{url} \tab \emph{optional} \tab an additional url for the author or the main affiliation\cr +\code{orcid} \tab \emph{optional} \tab the authors ORCID if available\cr +\code{email} \tab \emph{required} \tab the author's e-mail address\cr +\code{affiliation2} \tab \emph{optional} \tab name of the author's 2nd affiliation\cr +\code{address2} \tab \emph{optional} \tab address lines belonging to the author's 2nd affiliation +} + +\emph{Please note: Only one \code{url}, \code{orcid} and \code{email} can be provided per author.} +} From 42d35da1105d5b196208a573e0244ad53089ef92 Mon Sep 17 00:00:00 2001 From: RLumSK Date: Mon, 10 Aug 2020 12:51:34 +0200 Subject: [PATCH 09/36] #286 Update authors field to support two affiliations without using pipes not yet available in RStudio due to an older pandoc verison. The commit includes: + Updated template.tex as suggested by @cderv + Updated rjournal_article.R with more details in the documentation + Updated Rd-file + skeleton.Rmd update --- .../rjournal_article/skeleton/skeleton.Rmd | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd index f9aa6f23e..01a0f1fed 100644 --- a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd @@ -13,15 +13,14 @@ author: url: https://journal.r-project.org email: author2@work orcid: 0000-0002-9079-593X - affiliation: - - name: Affiliation 1 - - address: - - line 1 affiliation 1 - - line 2 affiliation 1 - - name: Affiliation 2 - - address: - - line 1 affiliation 2 - - line 2 affiliation 2 + affiliation: Affiliation 1 + address: + - line 1 affiliation 1 + - line 2 affiliation 1 + affiliation2: Affiliation 2 + address2: + - line 1 affiliation 2 + - line 2 affiliation 2 abstract: > An abstract of less than 150 words. preamble: | From 05b4dd980673c481e8bfe53f26eef4453ff341d7 Mon Sep 17 00:00:00 2001 From: RLumSK Date: Mon, 10 Aug 2020 13:42:01 +0200 Subject: [PATCH 10/36] Move the bibliography command into the YAML-header #286 --- .../rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd index 01a0f1fed..543d6b446 100644 --- a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd @@ -25,6 +25,7 @@ abstract: > An abstract of less than 150 words. preamble: | % Any extra LaTeX you need in the preamble +bibliography: RJreferences.bib output: rticles::rjournal_article --- @@ -53,5 +54,3 @@ x ## Summary This file is only a basic article template. For full details of _The R Journal_ style and information on how to prepare your article for submission, see the [Instructions for Authors](https://journal.r-project.org/share/author-guide.pdf). - -\bibliography{RJreferences} From b25b1b78e25081aa523409f2ac4c29a9b102da13 Mon Sep 17 00:00:00 2001 From: RLumSK Date: Tue, 11 Aug 2020 19:00:25 +0200 Subject: [PATCH 11/36] Request revision of PR #286 with issues addressed also from #287. Details: + Resolve author name separator problem (#287) + Function does not touch anymore the users files + Files are no collected in a seperate folder defined via output_dir in the YAML-header as part of the post processing + BIB-file renamed when in output_dir to match journal requirements + The user can now define an own bibliography file via the YAML-header + Measures implemented to avoid that users updating 'rticles' will run into trouble while rebuilding old files + Update skeleton.Rmd to meet new requirements + Update documentation --- R/rjournal_article.R | 126 +++++++++++++----- .../rjournal_article/skeleton/skeleton.Rmd | 11 +- man/rjournal_article.Rd | 14 +- 3 files changed, 116 insertions(+), 35 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index 869fef3e5..aae1911ae 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -1,11 +1,13 @@ #' @title R Journal format. #' #' @description Format for creating R Journal articles. Adapted from -#' \url{https://journal.r-project.org/submissions.html}. +#' \url{https://journal.r-project.org/submissions.html}. In order to ease the +#' manuscript preparation, the output is collected in a separate output directory, +#' which can be used for the submission. If needed file names are renamed automatically. #' #' @details #' -#' **The `author` field in the YAML-header** +#' **The `author` field in the YAML header** #' #' \tabular{lll}{ #' FIELD \tab TYPE \tab DESCRIPTION\cr @@ -21,36 +23,20 @@ #' #' *Please note: Only one `url`, `orcid` and `email` can be provided per author.* #' +#' **Other YAML fields** +#' +#' \tabular{lll}{ +#' FIELD \tab TYPE \tab DESCRIPTION\cr +#' `bibliography` \tab *with default* \tab the BibTeX file with the reference entries\cr +#' `output_dir` \tab *with default* \tab output directory where all the files are stored ready for submission +#' } +#' #' @param ...,citation_package Arguments to \code{rmarkdown::pdf_document}. #' #' @md #' @export rjournal_article <- function(..., citation_package = 'natbib') { - ## make sure that all files are correctly named according to the R journal - ## requirements https://journal.r-project.org/submissions.html - - ## get name of Bib-file and Rmd-file - Rmd_file_name <- list.files( - path = ".", pattern = ".Rmd", include.dirs = FALSE)[1] - bib_file_name <- list.files( - path = ".", pattern = ".bib", include.dirs = FALSE)[1] - - ## correct bibliography entry in Rmd-file - Rmd_file_text <- readLines(Rmd_file_name) - pat <- regexpr("(?<=\\\\bibliography{).+[^}]", Rmd_file_text, perl = TRUE) - regmatches(Rmd_file_text, pat) <- xfun::sans_ext(Rmd_file_name) - writeLines(text = Rmd_file_text, con = Rmd_file_name) - - ## correct bib-filename to match the name of the Rmd-file - file.rename(from = bib_file_name, to = paste0(xfun::sans_ext(Rmd_file_name), ".bib")) - - ## create R file with executable R code as requested - knitr::purl(Rmd_file_name, documentation = 1) - - ##remove objects - suppressWarnings(rm(Rmd_file_name, Rmd_file_text, bib_file_name)) - rmarkdown::pandoc_available('2.2', TRUE) base <- pdf_document_format( @@ -62,11 +48,16 @@ rjournal_article <- function(..., citation_package = 'natbib') { base$pandoc$to <- "latex" base$pandoc$ext <- ".tex" - base$post_processor <- function(metadata, utf8_input, output_file, clean, verbose) { - filename <- basename(output_file) - # underscores in the filename will be problematic in \input{filename}; - # pandoc will escape underscores but it should not, i.e., should be - # \input{foo_bar} instead of \input{foo\_bar} + base$post_processor <- + function(metadata, + utf8_input, + output_file, + clean, + verbose) { + filename <- basename(output_file) + # underscores in the filename will be problematic in \input{filename}; + # pandoc will escape underscores but it should not, i.e., should be + # \input{foo_bar} instead of \input{foo\_bar} if (filename != (filename2 <- gsub('_', '-', filename))) { file.rename(filename, filename2); filename <- filename2 } @@ -80,7 +71,76 @@ rjournal_article <- function(..., citation_package = 'natbib') { t <- find_resource("rjournal_article", "RJwrapper.tex") template_pandoc(m, t, "RJwrapper.tex", h, verbose) - tinytex::latexmk("RJwrapper.tex", base$pandoc$latex_engine, clean = clean) + ##compile TEX and return the output file path on exit + file <- tinytex::latexmk("RJwrapper.tex", base$pandoc$latex_engine, clean = clean) + on.exit(return(file)) + + ## below: additional treatment to meet the journal requirement; everything + ## is collected within a folder defined by output_dir in the YAML-header + + ##first we have to make sure that we do not break old code + ##check whether the new field exist, if not the user do not expect this + ##new folder and the writing on the hard drive and consequently full stop + if(is.null(metadata$output_dir)) + try(stop(), silent = TRUE) + + ##check also bibliography + if(is.null(metadata$bibliography)) + metadata$bibliography <- "RJreferences.bib" + + ##get file path and set new output directory + output_path <- dirname(normalizePath(output_file)) + output_dir <- paste(c(output_path, metadata$output_dir), collapse = "/") + + ##create subdirectory + dir.create(output_dir, showWarnings = FALSE) + + ##create additional R-code file + knitr::purl( + input = normalizePath(output_file), + output = paste0(output_dir,"/",xfun::sans_ext(output_file),".R"), + documentation = 1) + + ##copy files from working directory to user-defined output folder + file.copy(from = c( + output_file, + metadata$bibliography, + "RJwrapper.tex", + "RJwrapper.pdf" + ), to = output_dir, overwrite = TRUE) + + ##correct bib-filename to match the name of the TEX-file + file.rename(from = paste0(output_dir,"/",metadata$bibliography), + to = paste0(output_dir,"/",xfun::sans_ext(output_file), ".bib")) + + ##correct BIB-file ans TEX-file + temp_tex <- readLines(paste0(output_dir,"/", output_file)) + + ## correct bibliography + pat <- regexpr("(?<=\\\\bibliography{).+[^}]", temp_tex, perl = TRUE) + regmatches(temp_tex, pat) <- paste0(xfun::sans_ext(output_file), ".bib") + + + ##correct authors field to have pattern Author 1, Author 2 and Author 3 + authors <- + knitr::combine_words( + unlist( + strsplit( + x = temp_tex[grepl(pattern = "\\author{", x = temp_tex, fixed = TRUE)], + ","))) + + temp_tex[grepl(pattern = "\\author{", x = temp_tex, fixed = TRUE)] <- authors + + ##write TEX back to hard drive + writeLines(text = temp_tex, con = paste0(output_dir,"/", output_file)) + + ## copy and paste figures to output_dir. The LaTeX format make it a little bit + ## difficult, however, the R Journal allows only PDF or PNG figures + figures <- regmatches(temp_tex, regexec("(?<=\\\\includegraphics)(.*?){(.*?)}", temp_tex, perl = TRUE)) + figures <- as.character(stats::na.exclude(sapply(figures, function(x) x[3]))) + figures_files <- paste0(rep(figures, each = 2), c(".pdf", ".png")) + suppressWarnings(file.copy(from = figures_files, to = output_dir, overwrite = TRUE, recursive = FALSE)) + } # Mostly copied from knitr::render_sweave @@ -109,3 +169,5 @@ rjournal_article <- function(..., citation_package = 'natbib') { } + + diff --git a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd index 543d6b446..1638ce6e3 100644 --- a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd @@ -26,9 +26,18 @@ abstract: > preamble: | % Any extra LaTeX you need in the preamble bibliography: RJreferences.bib +output_dir: submission output: rticles::rjournal_article --- +```{r global_options, include=FALSE} +## these ensures that figures created within the R session +## materialise as files (otherwise they are only included in the final PDF) +## Note: If you change the output path, the files are not copied automatically +## to the directory defined via output_dir +knitr::opts_chunk$set(fig.path = "./") +``` + ## Introduction Introductory section which may include references in parentheses @@ -48,7 +57,7 @@ There will likely be several sections, perhaps including code snippets, such as: ```{r} x <- 1:10 -x +plot(x) ``` ## Summary diff --git a/man/rjournal_article.Rd b/man/rjournal_article.Rd index dc008cbea..61758ec88 100644 --- a/man/rjournal_article.Rd +++ b/man/rjournal_article.Rd @@ -11,10 +11,12 @@ rjournal_article(..., citation_package = "natbib") } \description{ Format for creating R Journal articles. Adapted from -\url{https://journal.r-project.org/submissions.html}. +\url{https://journal.r-project.org/submissions.html}. In order to ease the +manuscript preparation, the output is collected in a separate output directory, +which can be used for the submission. If needed file names are renamed automatically. } \details{ -\strong{The \code{author} field in the YAML-header} +\strong{The \code{author} field in the YAML header} \tabular{lll}{ FIELD \tab TYPE \tab DESCRIPTION\cr @@ -29,4 +31,12 @@ FIELD \tab TYPE \tab DESCRIPTION\cr } \emph{Please note: Only one \code{url}, \code{orcid} and \code{email} can be provided per author.} + +\strong{Other YAML fields} + +\tabular{lll}{ +FIELD \tab TYPE \tab DESCRIPTION\cr +\code{bibliography} \tab \emph{with default} \tab the BibTeX file with the reference entries\cr +\code{output_dir} \tab \emph{with default} \tab output directory where all the files are stored ready for submission +} } From d47a89b19d796e29974554dc52aa611010c63178 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 13:04:36 +0200 Subject: [PATCH 12/36] use rticles expected style --- R/rjournal_article.R | 45 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index aae1911ae..8e9cb99f1 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -48,16 +48,13 @@ rjournal_article <- function(..., citation_package = 'natbib') { base$pandoc$to <- "latex" base$pandoc$ext <- ".tex" - base$post_processor <- - function(metadata, - utf8_input, - output_file, - clean, - verbose) { - filename <- basename(output_file) - # underscores in the filename will be problematic in \input{filename}; - # pandoc will escape underscores but it should not, i.e., should be - # \input{foo_bar} instead of \input{foo\_bar} + base$post_processor <- function( + metadata, utf8_input, output_file, clean, verbose + ) { + filename <- basename(output_file) + # underscores in the filename will be problematic in \input{filename}; + # pandoc will escape underscores but it should not, i.e., should be + # \input{foo_bar} instead of \input{foo\_bar} if (filename != (filename2 <- gsub('_', '-', filename))) { file.rename(filename, filename2); filename <- filename2 } @@ -92,8 +89,8 @@ rjournal_article <- function(..., citation_package = 'natbib') { output_path <- dirname(normalizePath(output_file)) output_dir <- paste(c(output_path, metadata$output_dir), collapse = "/") - ##create subdirectory - dir.create(output_dir, showWarnings = FALSE) + ##create subdirectory + dir.create(output_dir, showWarnings = FALSE) ##create additional R-code file knitr::purl( @@ -116,20 +113,20 @@ rjournal_article <- function(..., citation_package = 'natbib') { ##correct BIB-file ans TEX-file temp_tex <- readLines(paste0(output_dir,"/", output_file)) - ## correct bibliography - pat <- regexpr("(?<=\\\\bibliography{).+[^}]", temp_tex, perl = TRUE) - regmatches(temp_tex, pat) <- paste0(xfun::sans_ext(output_file), ".bib") + ## correct bibliography + pat <- regexpr("(?<=\\\\bibliography{).+[^}]", temp_tex, perl = TRUE) + regmatches(temp_tex, pat) <- paste0(xfun::sans_ext(output_file), ".bib") - ##correct authors field to have pattern Author 1, Author 2 and Author 3 - authors <- - knitr::combine_words( - unlist( - strsplit( - x = temp_tex[grepl(pattern = "\\author{", x = temp_tex, fixed = TRUE)], - ","))) + ##correct authors field to have pattern Author 1, Author 2 and Author 3 + authors <- + knitr::combine_words( + unlist( + strsplit( + x = temp_tex[grepl(pattern = "\\author{", x = temp_tex, fixed = TRUE)], + ","))) - temp_tex[grepl(pattern = "\\author{", x = temp_tex, fixed = TRUE)] <- authors + temp_tex[grepl(pattern = "\\author{", x = temp_tex, fixed = TRUE)] <- authors ##write TEX back to hard drive writeLines(text = temp_tex, con = paste0(output_dir,"/", output_file)) @@ -153,7 +150,7 @@ rjournal_article <- function(..., citation_package = 'natbib') { } hook_input <- function(x, options) paste(c('\\begin{Sinput}', hilight_source(x, 'sweave', options), '\\end{Sinput}', ''), - collapse = '\n') + collapse = '\n') hook_output <- function(x, options) paste('\\begin{Soutput}\n', x, '\\end{Soutput}\n', sep = '') base$knitr$knit_hooks <- merge_list(base$knitr$knit_hooks, list( From c62918997e2d7883ea528d454191b18bb9337e94 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 13:11:57 +0200 Subject: [PATCH 13/36] these roxygen tags are not required as for other rticles help files --- R/rjournal_article.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index 8e9cb99f1..d585f081f 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -1,6 +1,6 @@ -#' @title R Journal format. +#' R Journal format. #' -#' @description Format for creating R Journal articles. Adapted from +#' Format for creating R Journal articles. Adapted from #' \url{https://journal.r-project.org/submissions.html}. In order to ease the #' manuscript preparation, the output is collected in a separate output directory, #' which can be used for the submission. If needed file names are renamed automatically. From 91bb325521d7ea8ae5e3e809f429fe35d64d9704 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 15:57:53 +0200 Subject: [PATCH 14/36] use purl on the input Rmd file and rename as the output file Using purl on the output tex file will not return the expected result. --- R/rjournal_article.R | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index d585f081f..39c7f8bc3 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -43,11 +43,30 @@ rjournal_article <- function(..., citation_package = 'natbib') { "rjournal_article", highlight = NULL, citation_package = citation_package, ... ) - # Render will generate tex file, post-process hook generates appropriate - # RJwrapper.tex and use pandoc to build pdf from that + # Render will generate tex file, post-knit hook gerenates the R file, + # post-process hook generates appropriate RJwrapper.tex and + # use pandoc to build pdf from that base$pandoc$to <- "latex" base$pandoc$ext <- ".tex" + # Generates R file expected as R journal requirement + # we do that in the post-knit hook do access input file path + pk <- base$post_knit + output_R <- NULL + base$post_knit <- function(metadata, input_file, runtime, ...) { + # run post_knit it exists + if (is.function(pk)) pk(metadata, input_file, runtime, ...) + + # purl the Rmd file to R code per requirement + temp_R <- tempfile(fileext = ".R") + output_R <<- knitr::purl( + input = input_file, output = temp_R, + documentation = 1, quiet = TRUE + ) + + NULL + } + base$post_processor <- function( metadata, utf8_input, output_file, clean, verbose ) { @@ -68,6 +87,10 @@ rjournal_article <- function(..., citation_package = 'natbib') { t <- find_resource("rjournal_article", "RJwrapper.tex") template_pandoc(m, t, "RJwrapper.tex", h, verbose) + # Copy purl-ed R file with the correct name + file.copy(output_R, xfun::with_ext(filename, "R")) + unlink(output_R) + ##compile TEX and return the output file path on exit file <- tinytex::latexmk("RJwrapper.tex", base$pandoc$latex_engine, clean = clean) on.exit(return(file)) @@ -92,12 +115,6 @@ rjournal_article <- function(..., citation_package = 'natbib') { ##create subdirectory dir.create(output_dir, showWarnings = FALSE) - ##create additional R-code file - knitr::purl( - input = normalizePath(output_file), - output = paste0(output_dir,"/",xfun::sans_ext(output_file),".R"), - documentation = 1) - ##copy files from working directory to user-defined output folder file.copy(from = c( output_file, From 39720c088e9a7391b1f1ad1fd5cc28f8d13828ab Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 16:04:54 +0200 Subject: [PATCH 15/36] Document bib file name requirement in skeleton --- .../templates/rjournal_article/skeleton/skeleton.Rmd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd index 1638ce6e3..2e6ef4291 100644 --- a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd @@ -25,7 +25,11 @@ abstract: > An abstract of less than 150 words. preamble: | % Any extra LaTeX you need in the preamble + +# per R journal requirement, the bib filename should be the same as the output +# tex file. Don't forget to rename the bib file and change this example value. bibliography: RJreferences.bib + output_dir: submission output: rticles::rjournal_article --- From c90e59ed64f4d6d80aca91325ae1383ddc0741b0 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 16:24:03 +0200 Subject: [PATCH 16/36] For now, we warn if a bib file is provided with another name than the output file --- R/rjournal_article.R | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index 39c7f8bc3..3e3303a0f 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -95,18 +95,18 @@ rjournal_article <- function(..., citation_package = 'natbib') { file <- tinytex::latexmk("RJwrapper.tex", base$pandoc$latex_engine, clean = clean) on.exit(return(file)) - ## below: additional treatment to meet the journal requirement; everything - ## is collected within a folder defined by output_dir in the YAML-header - - ##first we have to make sure that we do not break old code - ##check whether the new field exist, if not the user do not expect this - ##new folder and the writing on the hard drive and consequently full stop - if(is.null(metadata$output_dir)) - try(stop(), silent = TRUE) - - ##check also bibliography - if(is.null(metadata$bibliography)) - metadata$bibliography <- "RJreferences.bib" + # check bibliography name + bib_filename <- metadata$bibliography + if(!is.null(metadata$bibliography) && + xfun::sans_ext(bib_filename) != xfun::sans_ext(filename)) { + msg <- paste( + "Per R journal requirement, bibliography file and tex file should", + "have the same name.\nCurrently, you have a bib file {{bib_filename}} and", + "a tex file {{filename}}.\nDon't forget to rename and change ", + "the bibliography field in YAML header." + ) + warning(knitr::knit_expand(text = msg), call. = FALSE) + } ##get file path and set new output directory output_path <- dirname(normalizePath(output_file)) From 1002683b6511ef3743e8d22d0001e781a08532b2 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 16:25:58 +0200 Subject: [PATCH 17/36] do not put output in another folder --- R/rjournal_article.R | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index 3e3303a0f..db0eb18d7 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -108,32 +108,8 @@ rjournal_article <- function(..., citation_package = 'natbib') { warning(knitr::knit_expand(text = msg), call. = FALSE) } - ##get file path and set new output directory - output_path <- dirname(normalizePath(output_file)) - output_dir <- paste(c(output_path, metadata$output_dir), collapse = "/") - - ##create subdirectory - dir.create(output_dir, showWarnings = FALSE) - - ##copy files from working directory to user-defined output folder - file.copy(from = c( - output_file, - metadata$bibliography, - "RJwrapper.tex", - "RJwrapper.pdf" - ), to = output_dir, overwrite = TRUE) - - ##correct bib-filename to match the name of the TEX-file - file.rename(from = paste0(output_dir,"/",metadata$bibliography), - to = paste0(output_dir,"/",xfun::sans_ext(output_file), ".bib")) - ##correct BIB-file ans TEX-file - temp_tex <- readLines(paste0(output_dir,"/", output_file)) - - ## correct bibliography - pat <- regexpr("(?<=\\\\bibliography{).+[^}]", temp_tex, perl = TRUE) - regmatches(temp_tex, pat) <- paste0(xfun::sans_ext(output_file), ".bib") - + temp_tex <- readLines(output_file) ##correct authors field to have pattern Author 1, Author 2 and Author 3 authors <- @@ -146,14 +122,7 @@ rjournal_article <- function(..., citation_package = 'natbib') { temp_tex[grepl(pattern = "\\author{", x = temp_tex, fixed = TRUE)] <- authors ##write TEX back to hard drive - writeLines(text = temp_tex, con = paste0(output_dir,"/", output_file)) - - ## copy and paste figures to output_dir. The LaTeX format make it a little bit - ## difficult, however, the R Journal allows only PDF or PNG figures - figures <- regmatches(temp_tex, regexec("(?<=\\\\includegraphics)(.*?){(.*?)}", temp_tex, perl = TRUE)) - figures <- as.character(stats::na.exclude(sapply(figures, function(x) x[3]))) - figures_files <- paste0(rep(figures, each = 2), c(".pdf", ".png")) - suppressWarnings(file.copy(from = figures_files, to = output_dir, overwrite = TRUE, recursive = FALSE)) + writeLines(text = temp_tex, con = output_file) } From 8c2aafed950dbf0d95278fa1c4459b0a897ba5af Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 16:27:59 +0200 Subject: [PATCH 18/36] use read write function from xfun this also insure utf8 encoding assume in Rmarkdown. --- R/rjournal_article.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index db0eb18d7..e5accb044 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -109,7 +109,7 @@ rjournal_article <- function(..., citation_package = 'natbib') { } ##correct BIB-file ans TEX-file - temp_tex <- readLines(output_file) + temp_tex <- xfun::read_utf8(output_file) ##correct authors field to have pattern Author 1, Author 2 and Author 3 authors <- @@ -122,7 +122,7 @@ rjournal_article <- function(..., citation_package = 'natbib') { temp_tex[grepl(pattern = "\\author{", x = temp_tex, fixed = TRUE)] <- authors ##write TEX back to hard drive - writeLines(text = temp_tex, con = output_file) + xfun::write_utf8(text = temp_tex, con = output_file) } From 330febc943a2ba6fbb1fcbf30ee09973c6a4e24b Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 16:55:05 +0200 Subject: [PATCH 19/36] Tex post processing for authors should happen before rendering tex to pdf also remove a space and refactor --- R/rjournal_article.R | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index e5accb044..39c408e07 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -91,6 +91,20 @@ rjournal_article <- function(..., citation_package = 'natbib') { file.copy(output_R, xfun::with_ext(filename, "R")) unlink(output_R) + # post process TEX file + temp_tex <- xfun::read_utf8(output_file) + + ##correct authors field to have pattern Author 1, Author 2 and Author 3 + authors_line <- grepl(pattern = "\\author{", x = temp_tex, fixed = TRUE) + authors <- knitr::combine_words( + unlist( + strsplit( + x = temp_tex[authors_line], + ", "))) + temp_tex[authors_line] <- authors + + xfun::write_utf8(text = temp_tex, con = output_file) + ##compile TEX and return the output file path on exit file <- tinytex::latexmk("RJwrapper.tex", base$pandoc$latex_engine, clean = clean) on.exit(return(file)) @@ -108,22 +122,6 @@ rjournal_article <- function(..., citation_package = 'natbib') { warning(knitr::knit_expand(text = msg), call. = FALSE) } - ##correct BIB-file ans TEX-file - temp_tex <- xfun::read_utf8(output_file) - - ##correct authors field to have pattern Author 1, Author 2 and Author 3 - authors <- - knitr::combine_words( - unlist( - strsplit( - x = temp_tex[grepl(pattern = "\\author{", x = temp_tex, fixed = TRUE)], - ","))) - - temp_tex[grepl(pattern = "\\author{", x = temp_tex, fixed = TRUE)] <- authors - - ##write TEX back to hard drive - xfun::write_utf8(text = temp_tex, con = output_file) - } # Mostly copied from knitr::render_sweave From 021b2e694bce27f0fffb6026e3f24eec31760bfd Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 17:01:00 +0200 Subject: [PATCH 20/36] add three authors in skeleton to test --- .../templates/rjournal_article/skeleton/skeleton.Rmd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd index 2e6ef4291..ee30ecf27 100644 --- a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd @@ -21,6 +21,13 @@ author: address2: - line 1 affiliation 2 - line 2 affiliation 2 + - name: Author Three + url: https://journal.r-project.org + email: author3@work + affiliation: Affiliation + address: + - line 1 affiliation + - line 2 affiliation abstract: > An abstract of less than 150 words. preamble: | From 886e8b216cb382faf73d2cb7e16a03e7717daf37 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 17:38:38 +0200 Subject: [PATCH 21/36] isolate in a utils function and add test --- R/rjournal_article.R | 11 +---------- R/utils.R | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index 39c408e07..ecda9d2d1 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -93,16 +93,7 @@ rjournal_article <- function(..., citation_package = 'natbib') { # post process TEX file temp_tex <- xfun::read_utf8(output_file) - - ##correct authors field to have pattern Author 1, Author 2 and Author 3 - authors_line <- grepl(pattern = "\\author{", x = temp_tex, fixed = TRUE) - authors <- knitr::combine_words( - unlist( - strsplit( - x = temp_tex[authors_line], - ", "))) - temp_tex[authors_line] <- authors - + temp_tex <- post_process_authors(temp_tex) xfun::write_utf8(text = temp_tex, con = output_file) ##compile TEX and return the output file path on exit diff --git a/R/utils.R b/R/utils.R index 7b14eabb8..81b3be5e9 100644 --- a/R/utils.R +++ b/R/utils.R @@ -65,3 +65,17 @@ get_list_element <- function(x, names) { for (i in names[seq_len(n - 1)]) if (!is.list(x <- x[[i]])) return() x[[names[n]]] } + +# utils for post processing tex files + +post_process_authors <- function(text) { + # correct authors field to have pattern Author 1, Author 2 and Author 3 + authors_line <- grep(pattern = "\\author{", x = text, fixed = TRUE) + if (length(authors_line) != 0) { + new_authors <- knitr::combine_words( + strsplit(text[authors_line], split = ", ")[[1]] + ) + text[authors_line] <- new_authors + } + text +} From 4dd4a5f0d4f78a350ba24837d96f8b6161022068 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 17:41:05 +0200 Subject: [PATCH 22/36] move everything before pdf rendering --- R/rjournal_article.R | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index ecda9d2d1..24f14638a 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -77,15 +77,6 @@ rjournal_article <- function(..., citation_package = 'natbib') { if (filename != (filename2 <- gsub('_', '-', filename))) { file.rename(filename, filename2); filename <- filename2 } - m <- list(filename = xfun::sans_ext(filename)) - h <- get_list_element(metadata, c('output', 'rticles::rjournal_article', 'includes', 'in_header')) - h <- c(h, if (length(preamble <- unlist(metadata[c('preamble', 'header-includes')]))) { - f <- tempfile(fileext = '.tex'); on.exit(unlink(f), add = TRUE) - xfun::write_utf8(preamble, f) - f - }) - t <- find_resource("rjournal_article", "RJwrapper.tex") - template_pandoc(m, t, "RJwrapper.tex", h, verbose) # Copy purl-ed R file with the correct name file.copy(output_R, xfun::with_ext(filename, "R")) @@ -96,10 +87,6 @@ rjournal_article <- function(..., citation_package = 'natbib') { temp_tex <- post_process_authors(temp_tex) xfun::write_utf8(text = temp_tex, con = output_file) - ##compile TEX and return the output file path on exit - file <- tinytex::latexmk("RJwrapper.tex", base$pandoc$latex_engine, clean = clean) - on.exit(return(file)) - # check bibliography name bib_filename <- metadata$bibliography if(!is.null(metadata$bibliography) && @@ -113,6 +100,18 @@ rjournal_article <- function(..., citation_package = 'natbib') { warning(knitr::knit_expand(text = msg), call. = FALSE) } + # Create RJwrapper.tex per R Journal requirement + m <- list(filename = xfun::sans_ext(filename)) + h <- get_list_element(metadata, c('output', 'rticles::rjournal_article', 'includes', 'in_header')) + h <- c(h, if (length(preamble <- unlist(metadata[c('preamble', 'header-includes')]))) { + f <- tempfile(fileext = '.tex'); on.exit(unlink(f), add = TRUE) + xfun::write_utf8(preamble, f) + f + }) + t <- find_resource("rjournal_article", "RJwrapper.tex") + template_pandoc(m, t, "RJwrapper.tex", h, verbose) + + tinytex::latexmk("RJwrapper.tex", base$pandoc$latex_engine, clean = clean) } # Mostly copied from knitr::render_sweave From ddc51bf855defef8549f7b82407979c89dd94247 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 17:57:28 +0200 Subject: [PATCH 23/36] use keep_tex: true to keep the figures dir --- R/rjournal_article.R | 5 +++-- .../templates/rjournal_article/skeleton/skeleton.Rmd | 9 --------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index 24f14638a..e6e9315e1 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -35,12 +35,13 @@ #' #' @md #' @export -rjournal_article <- function(..., citation_package = 'natbib') { +rjournal_article <- function(..., keep_tex = TRUE, citation_package = 'natbib') { rmarkdown::pandoc_available('2.2', TRUE) base <- pdf_document_format( - "rjournal_article", highlight = NULL, citation_package = citation_package, ... + "rjournal_article", highlight = NULL, citation_package = citation_package, + keep_tex = keep_tex,... ) # Render will generate tex file, post-knit hook gerenates the R file, diff --git a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd index ee30ecf27..3045e6d00 100644 --- a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd @@ -37,18 +37,9 @@ preamble: | # tex file. Don't forget to rename the bib file and change this example value. bibliography: RJreferences.bib -output_dir: submission output: rticles::rjournal_article --- -```{r global_options, include=FALSE} -## these ensures that figures created within the R session -## materialise as files (otherwise they are only included in the final PDF) -## Note: If you change the output path, the files are not copied automatically -## to the directory defined via output_dir -knitr::opts_chunk$set(fig.path = "./") -``` - ## Introduction Introductory section which may include references in parentheses From da415647a88f481b70fd91e5c36a37146d7575f0 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 18:05:17 +0200 Subject: [PATCH 24/36] Document in skeleton about the requirements --- .../rjournal_article/skeleton/skeleton.Rmd | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd index 3045e6d00..0c6f4d1a6 100644 --- a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd @@ -65,3 +65,17 @@ plot(x) ## Summary This file is only a basic article template. For full details of _The R Journal_ style and information on how to prepare your article for submission, see the [Instructions for Authors](https://journal.r-project.org/share/author-guide.pdf). + +### About this format and the R Journal requirements + +`rticles::rjournal_article` will help you build the correct files requirements: + +* A R file will be generated automatically using `knitr::purl` - see +https://bookdown.org/yihui/rmarkdown-cookbook/purl.html for more information. +* A tex file will be generated from this Rmd file and correctly included in +`RJwapper.tex` as expected to build `RJwrapper.pdf`. +* All figure files will be kept in the default rmarkdown `*_files` folder. This +happens because `keep_tex = TRUE` by default in `rticles::rjournal_article` +* Only the bib filename is to modifed. An example bib file is included in the +template (`RJreferences.bib`) and you will have to name your bib file as the +tex, R, and pdf files. From ff749dd2dbfb2f2cc39c0c71398eccbf08374f82 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 18:15:49 +0200 Subject: [PATCH 25/36] if using markdown with roxygen, use it for all including tables and sections headers --- R/rjournal_article.R | 41 ++++++++++++++++++++++------------------- man/rjournal_article.Rd | 41 ++++++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index e6e9315e1..3e59182b1 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -5,31 +5,34 @@ #' manuscript preparation, the output is collected in a separate output directory, #' which can be used for the submission. If needed file names are renamed automatically. #' -#' @details +#' # About YAML header fields #' -#' **The `author` field in the YAML header** +#' This section documents some of the YAML fields that can be used with this +#' formats. #' -#' \tabular{lll}{ -#' FIELD \tab TYPE \tab DESCRIPTION\cr -#' `name` \tab *required* \tab name and surname of the author\cr -#' `affiliation` \tab *required* \tab name of the author's affiliation\cr -#' `address` \tab *required* \tab at least one address line for the affiliation\cr -#' `url` \tab *optional* \tab an additional url for the author or the main affiliation\cr -#' `orcid` \tab *optional* \tab the authors ORCID if available\cr -#' `email` \tab *required* \tab the author's e-mail address\cr -#' `affiliation2` \tab *optional* \tab name of the author's 2nd affiliation\cr -#' `address2` \tab *optional* \tab address lines belonging to the author's 2nd affiliation -#' } +#' +#' ## The `author` field in the YAML header +#' +#' | FIELD | TYPE | DESCRIPTION | +#' | ------ | ---- | ----------- | +#' | `name` | *required* | name and surname of the author | +#' | `affiliation` | *required* | name of the author's affiliation | +#' | `address` | *required* | at least one address line for the affiliation | +#' | `url` | *optional* | an additional url for the author or the main affiliation | +#' | `orcid` | *optional* | the authors ORCID if available | +#' | `email` | *required* | the author's e-mail address | +#' | `affiliation2` | *optional* | name of the author's 2nd affiliation | +#' | `address2` | *optional* | address lines belonging to the author's 2nd affiliation | #' #' *Please note: Only one `url`, `orcid` and `email` can be provided per author.* #' -#' **Other YAML fields** +#' ## Other YAML fields +#' +#' | FIELD | TYPE | DESCRIPTION | +#' | ----- | ---- | ----------- | +#' | `bibliography` | *with default* | the BibTeX file with the reference entries | +#' | `output_dir` | *with default* | output directory where all the files are stored ready for submission | #' -#' \tabular{lll}{ -#' FIELD \tab TYPE \tab DESCRIPTION\cr -#' `bibliography` \tab *with default* \tab the BibTeX file with the reference entries\cr -#' `output_dir` \tab *with default* \tab output directory where all the files are stored ready for submission -#' } #' #' @param ...,citation_package Arguments to \code{rmarkdown::pdf_document}. #' diff --git a/man/rjournal_article.Rd b/man/rjournal_article.Rd index 61758ec88..47a9f7678 100644 --- a/man/rjournal_article.Rd +++ b/man/rjournal_article.Rd @@ -4,7 +4,7 @@ \alias{rjournal_article} \title{R Journal format.} \usage{ -rjournal_article(..., citation_package = "natbib") +rjournal_article(..., keep_tex = TRUE, citation_package = "natbib") } \arguments{ \item{..., citation_package}{Arguments to \code{rmarkdown::pdf_document}.} @@ -15,28 +15,31 @@ Format for creating R Journal articles. Adapted from manuscript preparation, the output is collected in a separate output directory, which can be used for the submission. If needed file names are renamed automatically. } -\details{ -\strong{The \code{author} field in the YAML header} - -\tabular{lll}{ -FIELD \tab TYPE \tab DESCRIPTION\cr -\code{name} \tab \emph{required} \tab name and surname of the author\cr -\code{affiliation} \tab \emph{required} \tab name of the author's affiliation\cr -\code{address} \tab \emph{required} \tab at least one address line for the affiliation\cr -\code{url} \tab \emph{optional} \tab an additional url for the author or the main affiliation\cr -\code{orcid} \tab \emph{optional} \tab the authors ORCID if available\cr -\code{email} \tab \emph{required} \tab the author's e-mail address\cr -\code{affiliation2} \tab \emph{optional} \tab name of the author's 2nd affiliation\cr -\code{address2} \tab \emph{optional} \tab address lines belonging to the author's 2nd affiliation +\section{About YAML header fields}{ +This section documents some of the YAML fields that can be used with this +formats. +\subsection{The \code{author} field in the YAML header}{\tabular{lll}{ + FIELD \tab TYPE \tab DESCRIPTION \cr + \code{name} \tab \emph{required} \tab name and surname of the author \cr + \code{affiliation} \tab \emph{required} \tab name of the author's affiliation \cr + \code{address} \tab \emph{required} \tab at least one address line for the affiliation \cr + \code{url} \tab \emph{optional} \tab an additional url for the author or the main affiliation \cr + \code{orcid} \tab \emph{optional} \tab the authors ORCID if available \cr + \code{email} \tab \emph{required} \tab the author's e-mail address \cr + \code{affiliation2} \tab \emph{optional} \tab name of the author's 2nd affiliation \cr + \code{address2} \tab \emph{optional} \tab address lines belonging to the author's 2nd affiliation \cr } + \emph{Please note: Only one \code{url}, \code{orcid} and \code{email} can be provided per author.} +} -\strong{Other YAML fields} +\subsection{Other YAML fields}{\tabular{lll}{ + FIELD \tab TYPE \tab DESCRIPTION \cr + \code{bibliography} \tab \emph{with default} \tab the BibTeX file with the reference entries \cr + \code{output_dir} \tab \emph{with default} \tab output directory where all the files are stored ready for submission \cr +} -\tabular{lll}{ -FIELD \tab TYPE \tab DESCRIPTION\cr -\code{bibliography} \tab \emph{with default} \tab the BibTeX file with the reference entries\cr -\code{output_dir} \tab \emph{with default} \tab output directory where all the files are stored ready for submission } } + From 768a6bf1d5a13dcb5c59188475c127afb7a309b6 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 18:21:21 +0200 Subject: [PATCH 26/36] update function's documentation --- R/rjournal_article.R | 24 +++++++++++++++++++++--- man/rjournal_article.Rd | 24 +++++++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index 3e59182b1..e192a2238 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -1,9 +1,27 @@ #' R Journal format. #' #' Format for creating R Journal articles. Adapted from -#' \url{https://journal.r-project.org/submissions.html}. In order to ease the -#' manuscript preparation, the output is collected in a separate output directory, -#' which can be used for the submission. If needed file names are renamed automatically. +#' . +#' +#' @details +#' +#' This file is only a basic article template. For full details of _The R +#' Journal_ style and information on how to prepare your article for submission, +#' see the [Instructions for Authors](https://journal.r-project.org/share/author-guide.pdf) +#' +#' ## About this format and the R Journal requirements +#' +#' `rticles::rjournal_article` will help you build the correct files requirements: +#' +#' - A R file will be generated automatically using `knitr::purl` - see +#' https://bookdown.org/yihui/rmarkdown-cookbook/purl.html for more information. +#' - A tex file will be generated from this Rmd file and correctly included in +#' `RJwapper.tex` as expected to build `RJwrapper.pdf`. +#' - All figure files will be kept in the default rmarkdown `*_files` folder. This +#' happens because `keep_tex = TRUE` by default in `rticles::rjournal_article` +#' - Only the bib filename is to modifed. An example bib file is included in the +#' template (`RJreferences.bib`) and you will have to name your bib file as the +#' tex, R, and pdf files. #' #' # About YAML header fields #' diff --git a/man/rjournal_article.Rd b/man/rjournal_article.Rd index 47a9f7678..85d70e03f 100644 --- a/man/rjournal_article.Rd +++ b/man/rjournal_article.Rd @@ -11,9 +11,27 @@ rjournal_article(..., keep_tex = TRUE, citation_package = "natbib") } \description{ Format for creating R Journal articles. Adapted from -\url{https://journal.r-project.org/submissions.html}. In order to ease the -manuscript preparation, the output is collected in a separate output directory, -which can be used for the submission. If needed file names are renamed automatically. +\url{https://journal.r-project.org/submissions.html}. +} +\details{ +This file is only a basic article template. For full details of \emph{The R +Journal} style and information on how to prepare your article for submission, +see the \href{https://journal.r-project.org/share/author-guide.pdf}{Instructions for Authors} +\subsection{About this format and the R Journal requirements}{ + +\code{rticles::rjournal_article} will help you build the correct files requirements: +\itemize{ +\item A R file will be generated automatically using \code{knitr::purl} - see +https://bookdown.org/yihui/rmarkdown-cookbook/purl.html for more information. +\item A tex file will be generated from this Rmd file and correctly included in +\code{RJwapper.tex} as expected to build \code{RJwrapper.pdf}. +\item All figure files will be kept in the default rmarkdown \verb{*_files} folder. This +happens because \code{keep_tex = TRUE} by default in \code{rticles::rjournal_article} +\item Only the bib filename is to modifed. An example bib file is included in the +template (\code{RJreferences.bib}) and you will have to name your bib file as the +tex, R, and pdf files. +} +} } \section{About YAML header fields}{ This section documents some of the YAML fields that can be used with this From 07d84cf043b75a157271c5ce2fbb767992eb8312 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 18:31:46 +0200 Subject: [PATCH 27/36] missing comma --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index b04a4dd7a..85115796b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -40,7 +40,7 @@ Authors@R: c( person("Robrecht", "Cannoodt", role = c("aut", "cph"), email = "rcannood@gmail.com", comment = c(ORCID = "0000-0003-3641-729X", github = "rcannood")), person("Duncan", "Luguern", role = c("aut"), email = "duncan.luguern@gmail.com"), person("David M.", "Kaplan", role = c("aut", "ctb"), email = "dmkaplan2000@gmail.com", comment = c(ORCID = "0000-0001-6087-359X", github = "dmkaplan2000")), - person("Sebastian", "Kreutzer", role = c("aut"), email = "sebastian.kreutzer@aber.ac.uk", comment = c(ORCID = "0000-0002-0734-2199")) + person("Sebastian", "Kreutzer", role = c("aut"), email = "sebastian.kreutzer@aber.ac.uk", comment = c(ORCID = "0000-0002-0734-2199")), person("Shixiang", "Wang", role = c("aut", "ctb"), email = "w_shixiang@163.com", comment = c(ORCID = "0000-0001-9855-7357")), person('Jay', 'Hesselberth', role = c('aut', 'ctb'), email = 'jay.hesselberth@gmail.com', comment = c(ORCID = '0000-0002-6299-179X')), person("Alfredo", "Hernández", role = c("ctb"), email = "aldomann.designs@gmail.com", comment = c(ORCID = "0000-0002-2660-4545")), From 6f9ef7f50f7ffce3108069102ee9424a04b5e7ec Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 18:32:29 +0200 Subject: [PATCH 28/36] remove output_dir documentation --- R/rjournal_article.R | 2 -- man/rjournal_article.Rd | 1 - 2 files changed, 3 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index e192a2238..c2a57e4a5 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -49,8 +49,6 @@ #' | FIELD | TYPE | DESCRIPTION | #' | ----- | ---- | ----------- | #' | `bibliography` | *with default* | the BibTeX file with the reference entries | -#' | `output_dir` | *with default* | output directory where all the files are stored ready for submission | -#' #' #' @param ...,citation_package Arguments to \code{rmarkdown::pdf_document}. #' diff --git a/man/rjournal_article.Rd b/man/rjournal_article.Rd index 85d70e03f..5da473717 100644 --- a/man/rjournal_article.Rd +++ b/man/rjournal_article.Rd @@ -55,7 +55,6 @@ formats. \subsection{Other YAML fields}{\tabular{lll}{ FIELD \tab TYPE \tab DESCRIPTION \cr \code{bibliography} \tab \emph{with default} \tab the BibTeX file with the reference entries \cr - \code{output_dir} \tab \emph{with default} \tab output directory where all the files are stored ready for submission \cr } } From 3479c0bf7487dd23e69643e086027a180b2f192f Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 18:33:50 +0200 Subject: [PATCH 29/36] cosmetic --- R/rjournal_article.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index c2a57e4a5..4b7246181 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -60,7 +60,7 @@ rjournal_article <- function(..., keep_tex = TRUE, citation_package = 'natbib') base <- pdf_document_format( "rjournal_article", highlight = NULL, citation_package = citation_package, - keep_tex = keep_tex,... + keep_tex = keep_tex, ... ) # Render will generate tex file, post-knit hook gerenates the R file, From 132878355ad93bf2fad627f892f7297b348c1a27 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 18:34:48 +0200 Subject: [PATCH 30/36] comment improvement --- R/rjournal_article.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index 4b7246181..847fcf411 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -69,8 +69,8 @@ rjournal_article <- function(..., keep_tex = TRUE, citation_package = 'natbib') base$pandoc$to <- "latex" base$pandoc$ext <- ".tex" - # Generates R file expected as R journal requirement - # we do that in the post-knit hook do access input file path + # Generates R file expected by R journal requirement. + # We do that in the post-knit hook do access input file path. pk <- base$post_knit output_R <- NULL base$post_knit <- function(metadata, input_file, runtime, ...) { From 77ee0a1ffa72b6d76008f7a8a76e81c0ac781d08 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 18:43:22 +0200 Subject: [PATCH 31/36] output_file has been renamed in test and that is why it fails. --- R/rjournal_article.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index 847fcf411..95f15af75 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -103,9 +103,9 @@ rjournal_article <- function(..., keep_tex = TRUE, citation_package = 'natbib') unlink(output_R) # post process TEX file - temp_tex <- xfun::read_utf8(output_file) + temp_tex <- xfun::read_utf8(filename) temp_tex <- post_process_authors(temp_tex) - xfun::write_utf8(text = temp_tex, con = output_file) + xfun::write_utf8(text = temp_tex, con = filename) # check bibliography name bib_filename <- metadata$bibliography From ce8371c3582a4ae98a2d4c47194863c70c52f8c8 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 18:45:41 +0200 Subject: [PATCH 32/36] inherits params from pdf_document --- R/rjournal_article.R | 3 ++- man/rjournal_article.Rd | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/R/rjournal_article.R b/R/rjournal_article.R index 95f15af75..e5e8b8729 100644 --- a/R/rjournal_article.R +++ b/R/rjournal_article.R @@ -50,7 +50,8 @@ #' | ----- | ---- | ----------- | #' | `bibliography` | *with default* | the BibTeX file with the reference entries | #' -#' @param ...,citation_package Arguments to \code{rmarkdown::pdf_document}. +#' @inheritParams rmarkdown::pdf_document +#' @param ... Arguments to `rmarkdown::pdf_document. #' #' @md #' @export diff --git a/man/rjournal_article.Rd b/man/rjournal_article.Rd index 5da473717..493c5b6a2 100644 --- a/man/rjournal_article.Rd +++ b/man/rjournal_article.Rd @@ -7,7 +7,14 @@ rjournal_article(..., keep_tex = TRUE, citation_package = "natbib") } \arguments{ -\item{..., citation_package}{Arguments to \code{rmarkdown::pdf_document}.} +\item{...}{Arguments to `rmarkdown::pdf_document.} + +\item{keep_tex}{Keep the intermediate tex file used in the conversion to PDF} + +\item{citation_package}{The LaTeX package to process citations, \code{natbib} +or \code{biblatex}. Use \code{default} if neither package is to be used, +which means citations will be processed via the command +\command{pandoc-citeproc}.} } \description{ Format for creating R Journal articles. Adapted from From 2a1d6853bd0fbf5b8ebc82799d561c28bf78a3ff Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Aug 2020 18:48:01 +0200 Subject: [PATCH 33/36] And I forgot to add test in 886e8b2 --- tests/testit/test-utils.R | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/testit/test-utils.R diff --git a/tests/testit/test-utils.R b/tests/testit/test-utils.R new file mode 100644 index 000000000..719a0a2f8 --- /dev/null +++ b/tests/testit/test-utils.R @@ -0,0 +1,8 @@ +assert("last author is prepend with and ", { + (post_process_authors(c("\\title{title}", "\\author{John, Bob}")) %==% + c("\\title{title}", "\\author{John and Bob}")) + (post_process_authors("\\author{John, Bob, Mary}") %==% + "\\author{John, Bob, and Mary}") + unmodified <- c("No author line", "returns unmodified") + (post_process_authors(unmodified) %==% unmodified) +}) From 51d27bf4c22e58d5f6939ddb5c28be7b1c34a5ae Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Mon, 17 Aug 2020 12:12:40 +0200 Subject: [PATCH 34/36] use indices better to handles some edge cases with author lines and tests them --- R/utils.R | 32 ++++++++++++++++++++++++++------ tests/testit/test-utils.R | 25 +++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/R/utils.R b/R/utils.R index 2d1e1f411..6c2adf6f7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -69,13 +69,33 @@ pkg_file <- function(...) system.file(..., package = "rticles") # utils for post processing tex files post_process_authors <- function(text) { + + # --- # correct authors field to have pattern Author 1, Author 2 and Author 3 - authors_line <- grep(pattern = "\\author{", x = text, fixed = TRUE) - if (length(authors_line) != 0) { - new_authors <- knitr::combine_words( - strsplit(text[authors_line], split = ", ")[[1]] - ) - text[authors_line] <- new_authors + # --- + authors_lines_start <- grep(pattern = "^\\\\author\\{", x = text) + # if no author line do nothing + if (length(authors_lines_start) == 0L) return(text) + # if multiple author line, do nothing and warn as it is unusual + if (length(authors_lines_start) > 1L) { + warning( + "There should be only one use of `\\author{}` in the tex file. ", + "Post processing `\\author{}` is cancelled.", + call. = FALSE) + return(text) } + # find the authors lines range + authors_lines_end <- grep( + pattern = "\\}$", x = text[seq(authors_lines_start, length(text))] + )[1] + authors_lines_end <- authors_lines_end + (authors_lines_start - 1) + authors_lines_range <- seq(authors_lines_start, authors_lines_end) + # combine and write back + authors_lines <- paste0(text[authors_lines_range], collapse = "\n") + new_authors <- knitr::combine_words( + strsplit(authors_lines, split = ", ")[[1]] + ) + text[authors_lines_range] <- xfun::split_lines(new_authors) + # return modified text text } diff --git a/tests/testit/test-utils.R b/tests/testit/test-utils.R index 719a0a2f8..a7b1577be 100644 --- a/tests/testit/test-utils.R +++ b/tests/testit/test-utils.R @@ -1,8 +1,29 @@ assert("last author is prepend with and ", { + # if no author line, unmodified + unmodified <- c("No author line", "returns unmodified") + (post_process_authors(unmodified) %==% unmodified) + + # one author is unchanged + (post_process_authors("\\author{John Doe}") %==% + "\\author{John Doe}") + + # when 2 or more, add a 'and' (post_process_authors(c("\\title{title}", "\\author{John, Bob}")) %==% c("\\title{title}", "\\author{John and Bob}")) (post_process_authors("\\author{John, Bob, Mary}") %==% "\\author{John, Bob, and Mary}") - unmodified <- c("No author line", "returns unmodified") - (post_process_authors(unmodified) %==% unmodified) + + # Works also if authors on 2 or more lines in the tex file + (post_process_authors( + c("\\author{John, Bob,", "Mary, Dany}", "\\abstract{text}") + ) %==% + c("\\author{John, Bob,", "Mary, and Dany}", "\\abstract{text}")) + (post_process_authors( + c("\\title{title}", "\\author{John, Bob,", "Lucy, Ann,", "Mary, Dany}") + ) %==% + c("\\title{title}", "\\author{John, Bob,", "Lucy, Ann,", "Mary, and Dany}")) + + # handles the weird case where two or more \\authors are used in the document + unmodified <- c("\\author{John, Bob}", "some text", "\\author{Mary, Dany}") + (suppressWarnings(post_process_authors(unmodified)) %==% unmodified) }) From 55c5e826d35f3571d08e59d552e0b65da2a9b3d3 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 18 Aug 2020 11:18:58 +0200 Subject: [PATCH 35/36] Indicate to consult the help page of the funciton per PR comment https://github.com/rstudio/rticles/pull/286#discussion_r471722963 --- inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd index 0c6f4d1a6..42b9996b2 100644 --- a/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/rjournal_article/skeleton/skeleton.Rmd @@ -1,6 +1,7 @@ --- title: Capitalized Title Here author: + # see ?rjournal_article for more information - name: Author One affiliation: Affiliation address: From 95ae477ac8f546ad87568b810ee1a03ec95d0219 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 18 Aug 2020 11:32:11 +0200 Subject: [PATCH 36/36] increase version number --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 85115796b..7359ee41a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rticles Type: Package Title: Article Formats for R Markdown -Version: 0.14.3 +Version: 0.14.4 Authors@R: c( person("JJ", "Allaire", role = "aut", email = "jj@rstudio.com"), person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),