Skip to content

Commit

Permalink
Format titles using metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdnbradford committed Jul 18, 2024
1 parent 93e597b commit e448cff
Show file tree
Hide file tree
Showing 73 changed files with 432 additions and 347 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: lovecraftr
Type: Package
Title: H. P. Lovecraft's works, for text analysis
Version: 0.2.1
Version: 0.2.2
Authors@R:
person("Jordan", "Bradford", email = "[email protected]", role = c("aut", "cre"))
Description: A collection of H. P. Lovecraft's works as R datasets.
Expand Down
402 changes: 201 additions & 201 deletions R/data.R

Large diffs are not rendered by default.

Binary file added R/sysdata.rda
Binary file not shown.
18 changes: 13 additions & 5 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ template:

reference:
- title: Data
desc: >
{`lovecraftr`} contains the following datasets.

- subtitle: Data Frames
- contents:
- lovecraft

- subtitle: Novels
desc: Character vectors of novels
- contents:
- has_keyword("novella")

- subtitle: Short Stories
desc: Character vectors of short stories
contents:
- has_keyword("datasets")
- has_keyword("short")

- title: Functions
desc: >
{`lovecraftr`} contains the following functions.
contents:
- lovecraft_corpus
22 changes: 16 additions & 6 deletions data-raw/generate_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
# the raw txt files in data-raw/corpus


title_case <- function(x) {
stopwords <- c("and", "of", "the", "on", "at", "in", "with", "to", "that") # Add more stopwords if needed
words <- stringr::str_split(tolower(x), " ")[[1]]
words <- ifelse(words %in% stopwords & seq_along(words) != 1, words, stringr::str_to_title(words))
return(stringr::str_c(words, collapse = " "))
}

raw_txt_path <- file.path("data-raw", "corpus")
corpus <- list.files(raw_txt_path)
raw_txt_root <- "https://raw.githubusercontent.com/jrdnbradford/lovecraftr/main/data-raw/corpus/"
rda_root <- "https://github.com/jrdnbradford/lovecraftr/raw/main/data/"
metadata <- lovecraftr:::metadata

data_docs_file <- file.path("R", "data.R")
file.remove(data_docs_file)
Expand All @@ -19,12 +27,12 @@ header <- "# This documentation is generated by a script, do not edit by hand
"

docs_template <- "{header}
#' @title Dataset of \"{title}\"
#' @description A dataset containing text of H. P. Lovecraft's \"{title}\"
#' @title Dataset of {formatted_title}
#' @description A dataset containing text of H. P. Lovecraft's {formatted_title}
#' @usage data({dataset_name})
#' @format A character vector with {num_vectors} elements, with roughly 80 characters per line.
#' @docType data
#' @keywords datasets
#' @keywords datasets {type}
#' @source Public domain.
#' See the {raw_txt_link}
#' or download the {rda_link}.
Expand All @@ -43,9 +51,11 @@ for (txt in corpus) {
assign(txt, text)
do.call(usethis::use_data, list(dataset_name, overwrite = TRUE))

title <- head(text, 1)
raw_txt_link <- paste0("[raw text file", "]", "(", raw_txt_root, dataset_name, ")")
rda_link <- paste0("[RDA file", "]", "(", rda_root, dataset_name, ".rda)")
type <- subset(metadata, title == dataset_name)$type
title <- title_case(head(text, 1))
formatted_title <-ifelse(type == "novella", paste0("_", title, "_"), paste0("\"", title, "\""))
raw_txt_link <- paste0("[raw text file](", raw_txt_root, dataset_name, ")")
rda_link <- paste0("[RDA file](", rda_root, dataset_name, ".rda)")
dataset_docs <- glue::glue(docs_template)
docs <- c(docs, dataset_docs)

Expand Down
Binary file modified data/lovecraft.rda
Binary file not shown.
5 changes: 3 additions & 2 deletions man/at_the_mountains_of_madness.Rd

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

5 changes: 3 additions & 2 deletions man/azathoth.Rd

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

5 changes: 3 additions & 2 deletions man/beyond_the_wall_of_sleep.Rd

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

5 changes: 3 additions & 2 deletions man/celephais.Rd

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

5 changes: 3 additions & 2 deletions man/cool_air.Rd

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

5 changes: 3 additions & 2 deletions man/dagon.Rd

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

5 changes: 3 additions & 2 deletions man/dreams_in_the_witch_house.Rd

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

5 changes: 3 additions & 2 deletions man/ex_oblivione.Rd

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

5 changes: 3 additions & 2 deletions man/facts_concerning_the_late_arthur_jermyn_and_his_family.Rd

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

5 changes: 3 additions & 2 deletions man/from_beyond.Rd

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

5 changes: 3 additions & 2 deletions man/he.Rd

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

5 changes: 3 additions & 2 deletions man/herbert_west_reanimator.Rd

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

5 changes: 3 additions & 2 deletions man/hypnos.Rd

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

5 changes: 3 additions & 2 deletions man/imprisoned_with_the_pharoahs.Rd

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

5 changes: 3 additions & 2 deletions man/in_the_vault.Rd

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

5 changes: 3 additions & 2 deletions man/medusas_coil.Rd

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

5 changes: 3 additions & 2 deletions man/memory.Rd

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

Loading

0 comments on commit e448cff

Please sign in to comment.