Skip to content

Commit

Permalink
Stops adding "coast" to the "U.S. West"
Browse files Browse the repository at this point in the history
User instead inputs "U.S. West Coast", which allows users to also
use other phrases as requested in #9.

Close #9
  • Loading branch information
kellijohnson-NOAA committed Jul 9, 2023
1 parent cca0149 commit 4a8d4ac
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 127 deletions.
149 changes: 73 additions & 76 deletions R/draft.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,58 @@
#' stock assessment document written with \pkg{sa4ss}.
#'
#' @details
#' ## Wrapper for [rmarkdown::draft]
#' The function is based on [rmarkdown::draft] that creates
#' new R Markdown documents based on templates stored within R packages.
#' The [rticles](https://github.com/rstudio/rticles) R package stores the
#' most templates, mainly for the submission of manuscripts to journals.
#' ## Wrapper for [rmarkdown::draft()]
#' The function is based on [rmarkdown::draft()] that creates new R Markdown
#' documents based on templates stored within R packages. The
#' [rticles](https://github.com/rstudio/rticles) R package stores the most
#' templates, mainly for the submission of manuscripts to journals.
#'
#' User input for parameters such as `authors` and `species` help customize
#' the draft to your stock assessment document. Therefore,
#' users should focus on the input arguments that come before `type =`
#' because these will be specific to the stock assessment and are used to
#' set up the initial file structure.
#' User input for parameters such as `authors` and `species` help customize the
#' draft to your stock assessment document. Therefore, users should focus on
#' the input arguments that come before `type =` because these will be specific
#' to the stock assessment and are used to set up the initial file structure.
#'
#' ## File structure
#' A template contains two mandatory objects,
#' * template.yaml
#' * skeleton/skeleton.Rmd,
#' and optional files include those in a directory named resources
#' and additional files within the skeleton directory.
#' Because it is not known what your directory will be named, the
#' skeleton file is renamed to `00a.Rmd` by this function to ensure that
#' it comes first in bookdown's rendering of all of the .Rmd files,
#' which is done alphabetically unless users specify all the files,
#' an option that we do not really want to use.
#' and optional files include those in a directory named resources and
#' additional files within the skeleton directory. Because it is not known what
#' your directory will be named, the skeleton file is renamed to `00a.Rmd` by
#' this function to ensure that it comes first in bookdown's rendering of all
#' of the .Rmd files, which is done alphabetically unless users specify all the
#' files, an option that we do not really want to use.
#'
#' @template authors
#' @template species
#' @template latin
#' @template coast
#' @param type The name of the template you want to initiate.
#' The default template is `sa`, which stands for stock assessment.
#' As development for \pkg{sa4ss} progresses, expect to see more templates
#' become available. Available templates are listed in the default function call.
#' Specify a single character value from those available if you want to change
#' the type from the default.
#' @param type The name of the template you want to initiate. The default
#' template is `sa`, which stands for stock assessment. As development for
#' \pkg{sa4ss} progresses, expect to see more templates become available.
#' Available templates are listed in the default function call. Specify a
#' single character value from those available if you want to change the type
#' from the default.
#' @param create_dir A logical value that leads to the draft document being
#' placed in its own directory called `"doc"`.
#' The default value of \code{FALSE} uses the current working directory
#' rather than containing all of the files in a new directory,
#' which is helpful if you want to use your own name for the directory.
#' \code{TRUE} will create the new directory `"doc"` and copy of the necessary
#' files into it.
#' A third option also exists, `"default"`, which allows [rmarkdown::draft],
#' to determine the appropriate directory structure.
#' placed in its own directory called `"doc"`. The default value of
#' \code{FALSE} uses the current working directory rather than containing all
#' of the files in a new directory, which is helpful if you want to use your
#' own name for the directory. \code{TRUE} will create the new directory
#' `"doc"` and copy of the necessary files into it. A third option also
#' exists, `"default"`, which allows [rmarkdown::draft()], to determine the
#' appropriate directory structure.
#' @param edit A logical value, with a default of \code{FALSE}, specifying if
#' you want to open the indexing file for editing by default. The software chosen
#' by R is normally not ideal and
#' the file is not a file that is normally edited by users,
#' which is why \pkg{sa4ss} does not follow the default value used by
#' [rmarkdown::draft].
#' you want to open the indexing file for editing by default. The software
#' chosen by R is normally not ideal and the file is not a file that is
#' normally edited by users, which is why \pkg{sa4ss} does not follow the
#' default value used by [rmarkdown::draft()].
#' @param ... Additional arguments that you wish to pass to
#' [rmarkdown::draft]. See `args(rmarkdown::draft)`.
#' [rmarkdown::draft()]. See `args(rmarkdown::draft)`.
#'
#' @return Invisibly returns the file name of the document,
#' which will be the main indexing file that links to the auxiliary files.
#' If `edit = TRUE`, this file will be opened for editing.
#' @return
#' Invisibly returns the file name of the document, which will be the main
#' indexing file that links to the auxiliary files. If `edit = TRUE`, this file
#' will be opened for editing.
#' @examples
#' \dontrun{
#' sa4ss::draft()
Expand All @@ -69,43 +66,43 @@
#' @author Kelli F. Johnson
#'
draft <- function(authors,
species = "Species name",
latin = "Scientific name",
coast = "US West",
type = c("sa"),
create_dir = FALSE,
edit = FALSE,
...) {
type <- match.arg(type, several.ok = FALSE)
species = "Species name",
latin = "Scientific name",
coast = "U.S. West Coast",
type = c("sa"),
create_dir = FALSE,
edit = FALSE,
...) {
type <- match.arg(type, several.ok = FALSE)

filename <- rmarkdown::draft(
file = "doc.Rmd",
template = type,
package = "sa4ss",
create_dir = create_dir,
edit = edit,
...
)
filename <- rmarkdown::draft(
file = "doc.Rmd",
template = type,
package = "sa4ss",
create_dir = create_dir,
edit = edit,
...
)

newname <- gsub("doc.Rmd", "00a.Rmd", filename)
file.rename(filename, newname)
thedir <- dirname(newname)
write_title(
species = species, latin = latin, coast = coast,
fileout = file.path(thedir, formals(write_title)$fileout)
)
write_authors(authors,
fileout = file.path(thedir, formals(write_authors)$fileout)
)
spp <- species
# Make the first letter of the first word capital Cannot use title case or
# sentence case because I do not want to change the case of the second word,
# only the first.
Spp <- stringr::str_replace(spp, "^\\w{1}", toupper)
spp.sci <- latin
save(spp, Spp, spp.sci, coast, authors,
file = file.path(thedir, "00opts.Rdata")
)
newname <- gsub("doc.Rmd", "00a.Rmd", filename)
file.rename(filename, newname)
thedir <- dirname(newname)
write_title(
species = species, latin = latin, coast = coast,
fileout = file.path(thedir, formals(write_title)$fileout)
)
write_authors(authors,
fileout = file.path(thedir, formals(write_authors)$fileout)
)
spp <- species
# Make the first letter of the first word capital Cannot use title case or
# sentence case because I do not want to change the case of the second word,
# only the first.
Spp <- stringr::str_replace(spp, "^\\w{1}", toupper)
spp.sci <- latin
save(spp, Spp, spp.sci, coast, authors,
file = file.path(thedir, "00opts.Rdata")
)

return(invisible(newname))
return(invisible(newname))
}
2 changes: 1 addition & 1 deletion R/write_title.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ write_title <- function(species,
"---\n",
yaml::as.yaml(list(title = paste0(
"Status of ", species, " (_", latin, "_)",
" along the ", coast, " coast in ", year
" along the ", coast, " in ", year
))),
"---"
),
Expand Down
89 changes: 45 additions & 44 deletions man/draft.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions man/roxygen/templates/coast.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#' @param coast A character string specifying which part of the coast
#' the stock assessment includes. For example, \code{"US West"}.
#' Do not include \code{"coast"} because it will be added internally.
#' @param coast A character string specifying which part of the coast the stock
#' assessment includes. For example, `"U.S. West Coast"`, which is the
#' default, will be used to create the following title: "Status of common
#' name (latin name) along the U.S. West Coast in 2010". Previously, the word
#' coast was added internally to the text, this is no longer the default
#' behavior of sa4ss and instead you must explicitly add the word, which
#' allows users to have more flexibility. For example, "California Coast from
#' Point Conception north" is a viable option.
11 changes: 8 additions & 3 deletions man/write_title.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a8d4ac

Please sign in to comment.