|
3 | 3 | #' @description |
4 | 4 | #' `r lifecycle::badge('deprecated')` |
5 | 5 | #' |
6 | | -#' This function is now deprecated in favor of the [**rjtools**](https://rjournal.github.io/rjtools/) package |
7 | | -#' which is now officialy recommanded by R Journal <https://rjournal.github.io/submissions.html>. See below for document |
| 6 | +#' This function is now defunct in favor of the [**rjtools**](https://rjournal.github.io/rjtools/) package |
| 7 | +#' which is now officialy recommanded by R Journal <https://rjournal.github.io/submissions.html>. |
8 | 8 | #' |
9 | | -#' @details # About this format and the R Journal requirements |
10 | | -#' |
11 | | -#' Format for creating R Journal articles. Adapted from |
12 | | -#' <https://journal.r-project.org/submissions.html>. |
13 | | -#' |
14 | | -#' This file is only a basic article template. For full details of _The R |
15 | | -#' Journal_ style and information on how to prepare your article for submission, |
16 | | -#' see the [Instructions for Authors](https://journal.r-project.org/share/author-guide.pdf) |
17 | | -#' |
18 | | - |
19 | | -#' |
20 | | -#' `rticles::rjournal_article` will help you build the correct files requirements: |
21 | | -#' |
22 | | -#' - A R file will be generated automatically using `knitr::purl` - see |
23 | | -#' https://bookdown.org/yihui/rmarkdown-cookbook/purl.html for more information. |
24 | | -#' - A tex file will be generated from this Rmd file and correctly included in |
25 | | -#' `RJwapper.tex` as expected to build `RJwrapper.pdf`. |
26 | | -#' - All figure files will be kept in the default rmarkdown `*_files` folder. This |
27 | | -#' happens because `keep_tex = TRUE` by default in `rticles::rjournal_article` |
28 | | -#' - Only the bib filename is to be modified. An example bib file is included in the |
29 | | -#' template (`RJreferences.bib`) and you will have to name your bib file as the |
30 | | -#' tex, R, and pdf files. |
31 | | -#' |
32 | | -#' # About YAML header fields |
33 | | -#' |
34 | | -#' This section documents some of the YAML fields that can be used with this |
35 | | -#' formats. |
36 | | -#' |
37 | | -#' ## The `author` field in the YAML header |
38 | | -#' |
39 | | -#' | FIELD | TYPE | DESCRIPTION | |
40 | | -#' | ------ | ---- | ----------- | |
41 | | -#' | `name` | *required* | name and surname of the author | |
42 | | -#' | `affiliation` | *required* | name of the author's affiliation | |
43 | | -#' | `address` | *required* | at least one address line for the affiliation | |
44 | | -#' | `url` | *optional* | an additional url for the author or the main affiliation | |
45 | | -#' | `orcid` | *optional* | the authors ORCID if available | |
46 | | -#' | `email` | *required* | the author's e-mail address | |
47 | | -#' | `affiliation2` | *optional* | name of the author's 2nd affiliation | |
48 | | -#' | `address2` | *optional* | address lines belonging to the author's 2nd affiliation | |
49 | | -#' |
50 | | -#' *Please note: Only one `url`, `orcid` and `email` can be provided per author.* |
51 | | -#' |
52 | | -#' ## Other YAML fields |
53 | | -#' |
54 | | -#' | FIELD | TYPE | DESCRIPTION | |
55 | | -#' | ----- | ---- | ----------- | |
56 | | -#' | `bibliography` | *with default* | the BibTeX file with the reference entries | |
57 | | -#' |
58 | | -#' @inheritParams rmarkdown::pdf_document |
59 | | -#' @param ... Arguments to [rmarkdown::pdf_document()]. |
60 | | -#' @export |
| 9 | +#' @keywords internal |
61 | 10 | rjournal_article <- function(..., keep_tex = TRUE, citation_package = "natbib") { |
62 | 11 |
|
63 | | - lifecycle::deprecate_warn("0.25", "rjournal_article()", "rjtools::rjournal_pdf_article()", details = "See official recommandation at https://rjournal.github.io/submissions.html") |
64 | | - rmarkdown::pandoc_available("2.2", TRUE) |
65 | | - |
66 | | - base <- pdf_document_format( |
67 | | - "rjournal", |
68 | | - highlight = NULL, citation_package = citation_package, |
69 | | - keep_tex = keep_tex, ... |
70 | | - ) |
71 | | - |
72 | | - # Render will generate tex file, post-knit hook gerenates the R file, |
73 | | - # post-process hook generates appropriate RJwrapper.tex and |
74 | | - # use pandoc to build pdf from that |
75 | | - base$pandoc$to <- "latex" |
76 | | - base$pandoc$ext <- ".tex" |
77 | | - |
78 | | - # Generates R file expected by R journal requirement. |
79 | | - # We do that in the post-knit hook do access input file path. |
80 | | - pk <- base$post_knit |
81 | | - output_R <- NULL |
82 | | - base$post_knit <- function(metadata, input_file, runtime, ...) { |
83 | | - # run post_knit it exists |
84 | | - if (is.function(pk)) pk(metadata, input_file, runtime, ...) |
85 | | - |
86 | | - # purl the Rmd file to R code per requirement |
87 | | - temp_R <- tempfile(fileext = ".R") |
88 | | - output_R <<- knitr::purl(input_file, temp_R, documentation = 1, quiet = TRUE) |
89 | | - # Add magic comment about '"do not edit" (rstudio/rstudio#2082) |
90 | | - xfun::write_utf8(c( |
91 | | - "# Generated by `rjournal_article()` using `knitr::purl()`: do not edit by hand", |
92 | | - sprintf("# Please edit %s to modify this file", input_file), |
93 | | - "", |
94 | | - xfun::read_utf8(output_R) |
95 | | - ), output_R) |
96 | | - |
97 | | - NULL |
98 | | - } |
99 | | - |
100 | | - base$post_processor <- function(metadata, utf8_input, output_file, clean, verbose) { |
101 | | - filename <- basename(output_file) |
102 | | - # underscores in the filename will be problematic in \input{filename}; |
103 | | - # pandoc will escape underscores but it should not, i.e., should be |
104 | | - # \input{foo_bar} instead of \input{foo\_bar} |
105 | | - if (filename != (filename2 <- gsub("_", "-", filename))) { |
106 | | - file.rename(filename, filename2) |
107 | | - filename <- filename2 |
108 | | - } |
109 | | - |
110 | | - # Copy purl-ed R file with the correct name |
111 | | - dest_file <- xfun::with_ext(filename, "R") |
112 | | - our_file <- TRUE |
113 | | - if (file.exists(dest_file)) { |
114 | | - # we check this file is generated by us |
115 | | - # otherwise we leave it as is and warn |
116 | | - current_r <- xfun::read_utf8(dest_file) |
117 | | - our_file <- grepl("Generated.*rjournal_article.*do not edit by hand", current_r[1]) |
118 | | - if (!our_file) { |
119 | | - warning( |
120 | | - sprintf("R file with name '%s' already exists.", dest_file), |
121 | | - "\nIt will not be overwritten by the one generated", |
122 | | - " during rendering using `knitr::purl()`.", |
123 | | - "\nRemove the existing file to obtain the generated one.", |
124 | | - call. = FALSE |
125 | | - ) |
126 | | - } |
127 | | - } |
128 | | - if (our_file) { |
129 | | - # we only overwrite if it is our file |
130 | | - file.copy(output_R, xfun::with_ext(filename, "R"), overwrite = TRUE) |
131 | | - } |
132 | | - unlink(output_R) |
133 | | - |
134 | | - # post process TEX file |
135 | | - temp_tex <- xfun::read_utf8(filename) |
136 | | - temp_tex <- post_process_authors(temp_tex) |
137 | | - xfun::write_utf8(temp_tex, filename) |
138 | | - |
139 | | - # check bibliography name |
140 | | - bib_filename <- metadata$bibliography |
141 | | - if (length(bib_filename) == 1 && |
142 | | - xfun::sans_ext(bib_filename) != xfun::sans_ext(filename)) { |
143 | | - msg <- paste0( |
144 | | - "Per R journal requirement, bibliography file and tex file should", |
145 | | - " have the same name. Currently, you have a bib file ", bib_filename, |
146 | | - " and a tex file ", filename, ". Don't forget to rename and change", |
147 | | - " the bibliography field in the YAML header." |
148 | | - ) |
149 | | - warning(msg, call. = FALSE) |
150 | | - } |
151 | | - |
152 | | - # Create RJwrapper.tex per R Journal requirement |
153 | | - m <- list(filename = xfun::sans_ext(filename)) |
154 | | - h <- get_list_element(metadata, c("output", "rticles::rjournal_article", "includes", "in_header")) |
155 | | - h <- c(h, if (length(preamble <- unlist(metadata[c("preamble", "header-includes")]))) { |
156 | | - f <- tempfile(fileext = ".tex") |
157 | | - on.exit(unlink(f), add = TRUE) |
158 | | - xfun::write_utf8(preamble, f) |
159 | | - f |
160 | | - }) |
161 | | - t <- find_resource("rjournal", "RJwrapper.tex") |
162 | | - template_pandoc(m, t, "RJwrapper.tex", h, verbose) |
163 | | - |
164 | | - tinytex::latexmk("RJwrapper.tex", base$pandoc$latex_engine, clean = clean) |
165 | | - } |
166 | | - |
167 | | - # Mostly copied from knitr::render_sweave |
168 | | - base$knitr$opts_chunk$comment <- "#>" |
| 12 | + lifecycle::deprecate_stop("0.25", "rjournal_article()", "rjtools::rjournal_pdf_article()", details = "See official recommandation at https://rjournal.github.io/submissions.html") |
169 | 13 |
|
170 | | - set_sweave_hooks(base) |
171 | 14 | } |
0 commit comments