Package 'notestar'

Title: Notebooks Using 'Targets' and 'Bookdown'
Description: 'Targets' is an R package for dependency and build management in data analysis projects. This package provides a set of targets and project infrastructure to create 'bookdown'-based notebooks using 'targets'.
Authors: Tristan Mahr [aut, cre]
Maintainer: Tristan Mahr <[email protected]>
License: GPL (>= 3)
Version: 0.0.0.9003
Built: 2024-11-01 03:24:48 UTC
Source: https://github.com/tjmahr/notestar

Help Index


Open the notebook in a browser

Description

Open the notebook in a browser

Usage

notebook_browse(file = NULL)

Arguments

file

full path to the notebook file. Defaults to NULL in which case it finds the path using targets.

Value

This function is called for its side effects so it return NULL invisibly.


Create a new notebook page

Description

Creates a file with pattern ⁠[notebook_dir]/[date][-slug].Rmd⁠.

Usage

notebook_create_page(slug = NULL, date = NULL, open = TRUE)

Arguments

slug

Optional "slug" (label) for the post. Defaults to "".

date

Optional data to use. This date should have the format YYYY-MM-DD. Defaults to the current date.

open

Whether to open the new file for editing. Defaults to rlang::is_interactive().

Value

Invisible returns the relative path to the created file.


Set default knitr options for notebook knitting

Description

These options are used in the knitr-helpers.R file.

Usage

notebook_set_opts_knit()

notebook_set_opts_chunk()

notebook_set_markdown_hooks()

Value

a list containing the default options used


Write out a yaml-file and return the path

Description

This function is a wrapper over yaml::write_yaml() that works with file targets.

Usage

notebook_write_yaml(x, file, ...)

Arguments

x, file, ...

arguments passed to yaml::write_yaml().

Value

the yaml file is written and the value of file is returned


Assemble knitted notebook md files into a single-page bookdown document

Description

Assemble knitted notebook md files into a single-page bookdown document

Usage

tar_notebook(
  subdir_output = "docs",
  extra_deps = list(),
  use_downlit = FALSE,
  markdown_document2_args = list()
)

Arguments

subdir_output

Subdirectory of dir_md which will contain final html file produced by bookdown. Defaults to "docs".

extra_deps

A list of extra dependencies. These should be the names of targets defined elsewhere in the dependencies graph. Defaults to list(). Use this argument, for example, to force a notebook to depend on a .css file.

use_downlit

whether to post-process the notebook with the downlit syntax highlighter. Default is FALSE.

markdown_document2_args

arguments to pass onto bookdown::markdown_document2(). Defaults to list().

Details

The list of targets produced includes:

  • notebook_output_yaml, a file target for ⁠_output.yml⁠ (used by bookdown to set output format options).

  • notebook_bookdown_yaml, a file target for ⁠_bookdown.yml⁠ (used by bookdown to collate pages).

  • notebook, a file target for the final assembled html file used by bookdown.

The only output format supported is an html file produced by cleanrmd::html_document_clean().

Value

A list of targets.


Create index.Rmd file

Description

This function creates the index.Rmd file for the notebook and sets YAML metadata in the file. It also detects CSL and bibliography file dependencies.

Usage

tar_notebook_index_rmd(
  title = "Notebook title",
  author = "Author name",
  bibliography = ymlthis::yml_blank(),
  csl = ymlthis::yml_blank(),
  index_rmd_body_lines = "",
  ...,
  .list = rlang::list2(...)
)

Arguments

title

Title to use for the notebook. Defaults to "Notebook title".

author

Author name for the notebook. Defaults to "Author Name". Multiple authors, email and affiliations can used by using a list list(name = names, email = emails). See ymlthis::yml_author().

bibliography

Name of a .bib file in the dir_notebook rmd folder. This file is copied to ⁠[dir_md]/assets/[bibliography]⁠ and saved in the YAML metadata in index.Rmd as "./assets/[bibliography]". Defaults to ymlthis::yml_blank(). This file is then tracked with targets and set as a dependency for tar_notebook().

csl

Name of a .csl file in the dir_notebook rmd folder. This file is copied to ⁠[dir_md]/assets/[csl]⁠ and saved in the YAML metadata in index.Rmd as "./assets/[csl]". Defaults to ymlthis::yml_blank(). This file is then tracked with targets and set as a dependency for tar_notebook().

index_rmd_body_lines

optional character vector to use for body text in index.Rmd. Defaults to "".

...

Additional key-value pairs for setting fields in the yml metadata. For example, subtitle = "Status: Project completed" would add a subtitle to the index.Rmd file and that subtitle would appear in the notebook. These fields cannot include "date" or "site".

.list

Alternatively, these YAML fields may be set using a list. Any key-value pairs in this list will override options set by arguments. For example, an author entry in .list would override the value in the author parameter.

Value

a list of targets:

  • notebook_bibliography_user, notebook_csl_user: file targets for the bibliography and csl files in the dir_notebook user folder.

  • notebook_bibliography_asset, notebook_csl_asset: file targets for the bibliography and csl files in the dir_md assets folder. These command to build these targets to copy them.

  • notebook_index_rmd: file target for the index.Rmd file.

If any of these file targets is not used, an empty target list() is passed along.


Create targets to knit notebook Rmd files

Description

Create targets to knit notebook Rmd files

Usage

tar_notebook_pages()

Details

The list of targets produced includes:

  • notebook_helper_user, a file for the user's helper R script.

  • notebook_helper, a mirrored copy of the notebook_helper_user

  • one file target for each input Rmd file. Any targets used with tar_read() or tar_load() inside these files are detected and checked for changes.

  • one file target for each output md file.

  • notebook_rmds, a combined target for the input .Rmd files.

  • notebook_mds, a combined target for the output .md files.

Value

A list of targets.


Create a brand new notebook with default settings

Description

Create a brand new notebook with default settings

Usage

use_notestar(
  dir_project = ".",
  dir_notebook = "notebook",
  dir_md = "notebook/book",
  notebook_helper = "knitr-helpers.R",
  cleanrmd_theme = "water",
  notebook_filename = "notebook",
  open = interactive()
)

use_notestar_makefile(dir_project = ".")

use_notestar_references(dir_project = ".")

Arguments

dir_project

file-path to the base/root folder of the project. Defaults to "." which is the current working directory.

dir_notebook

Name of the directory containing the Rmd files. It should be a relative path from the project root. Defaults to "notebook"

dir_md

Name of the directory to contain md files (knitted Rmd files). It should be a relative path from the project root. Defaults to "notebook/book".

notebook_helper

Filename for an R script to run before knitting each Rmd file and rendering the notebook with bookdown. The file must be in dir_md. Defaults to "knitr-helpers.R" so the default location is ⁠"notebook/knitr_helpers.R⁠.

cleanrmd_theme

Theme to use for cleanrmd::html_document_clean(). Defaults to "water".

notebook_filename

Name to use for the final html file. Defaults to "notebook" which produces "notebook.html".

open

whether to open ⁠_targets.R⁠, notebook/index.Rmd, and R/functions.R when they are created. Defaults to interactive() (whether the code is being called interactively).

Value

use_notestar_makefile() creates a Makefile that will build or clean a targets-based workflow.

use_notestar_references() adds the files "refs.bib" and "apa.csl" to dir_notebook.