Skip to contents

This function takes an object as produced by split_to_toots() (or the toot_df stored in that object in $df), replaces the image URLs by full URLs, and checks the toot length, whether all images exist, whether no image is too large, and whether the alt texts are long enough. It also appends the results of the checks and the full image path to the toot_df and then returns it (i.e. quartodon::prep_and_check_toot_df() always returns a data frame).

Usage

prep_and_check_toot_df(
  x,
  instance = getOption("quartodon_instance", NULL),
  postsPath = NULL,
  minAltLength = getOption("quartodon_minAltLength", 10),
  max_characters = getOption("quartodon_max_characters", 500),
  characters_reserved_per_url = getOption("quartodon_characters_reserved_per_url", 23),
  image_size_limit = getOption("image_size_limit", 8 * 1024 * 1024),
  stopOnErrors = getOption("stopOnErrors", TRUE),
  tokenname = getOption("quartodon_tokenname", "RTOOT_DEFAULT_TOKEN")
)

Arguments

x

The object produced by a call to split_to_toots(), or the toot_df contained in it (in $df).

instance

Optionally, the instance where you want to toot to. If provided, its API is called to get its policies, which are then used to override the default values of max_characters, characters_reserved_per_url, and image_size_limit. If not specified, but if a valid token is stored in the environment variable specified by rokenname, the instance is taken from that token.

postsPath

The path to the posts that were processed to produce the toot_df provided as x.

minAltLength

The minimum length of alt texts for the images.

max_characters

The maximum number of characters for a toot.

characters_reserved_per_url

The number of characters counted for URLs.

image_size_limit

The maximum file size for images.

stopOnErrors

Whether to stop when a verification fails (TRUE) or whether to just store the errors in a column called errors.

tokenname

The name of the environment variable containing the rtoot token produced with rtoot::auth_setup() and rtoot::convert_token_to_envvar().

Value

The toot_df passed as x, with some added columns.

Examples

### Get example post directory
examplePostDir <-
  system.file("example-post",
              package = "quartodon");

### Get an example text (see the intro vignette)
exampleText <-
  readLines(
    file.path(examplePostDir, "quartodon.Rmd"),
    encoding = "UTF-8"
  );

### Extract the toots
extractedToots <- quartodon::split_to_toots(
  exampleText
);

### Append the thread counters
toot_df <- quartodon::append_thread_counter(
  extractedToots
);

### Prepare and check the toots (for length, existing
### images, etc)
toot_df <- quartodon::prep_and_check_toot_df(
  toot_df,
  postsPath = examplePostDir
);