Type: | Package |
Title: | Create Flashcards of Terms and Definitions |
Version: | 0.3.0 |
Maintainer: | Jeffrey R. Stevens <jeffrey.r.stevens@protonmail.com> |
Description: | Provides functions for creating flashcard decks of terms and definitions. This package creates HTML slides using 'revealjs' that can be viewed in the 'RStudio' viewer or a web browser. Users can create flashcards from either existing built-in decks or create their own from CSV files or vectors of function names. |
License: | MIT + file LICENSE |
URL: | https://github.com/JeffreyRStevens/flashr, https://jeffreyrstevens.github.io/flashr/ |
BugReports: | https://github.com/JeffreyRStevens/flashr/issues |
Depends: | R (≥ 2.10) |
Imports: | cli, curl, gh, httr, memoise, revealjs, rmarkdown, testthat, utils |
Suggests: | covr, knitr, litedown, withr |
VignetteBuilder: | knitr |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-05-07 18:34:53 UTC; jstevens |
Author: | Jeffrey R. Stevens
|
Repository: | CRAN |
Date/Publication: | 2025-05-07 18:50:02 UTC |
flashr: Create Flashcards of Terms and Definitions
Description
Provides functions for creating flashcard decks of terms and definitions. This package creates HTML slides using 'revealjs' that can be viewed in the 'RStudio' viewer or a web browser. Users can create flashcards from either existing built-in decks or create their own from CSV files or vectors of function names.
Author(s)
Maintainer: Jeffrey R. Stevens jeffrey.r.stevens@protonmail.com (ORCID) [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/JeffreyRStevens/flashr/issues
Build data frame of functions for input to flashcard()
Description
To create a data frame of functions that can be used to create a flashcard
deck, use build_functions_df()
. This function calls extract_functions()
to find the functions if the file
argument is specified. Otherwise, users
can pass a character vector of function names to the fs
argument. Either
way, a title must be passed to title
to create the data frame.
Users can then either complete the description column of the data frame
with their own descriptions or set the desc
argument to TRUE to use
descriptions from
flashr_decks.
Usage
build_functions_df(file = NULL, fs = NULL, title, desc = TRUE, omit = TRUE)
Arguments
file |
Character string of file name for text that includes code blocks. Can be local file or URL. |
fs |
If not using a file, character vector of functions
[do not include |
title |
Character string of title for flashcard deck (required) |
desc |
Logical for whether to search for descriptions from flashr_decks (default is TRUE, which includes descriptions from flashr_decks). |
omit |
Logical for whether to omit terms that have no descriptions from flashr_decks (default is TRUE, which omits terms with no descriptions). |
Value
Data frame suitable to include in flashcard()
.
See Also
Other functions for extracting code and functions:
extract_code()
,
extract_functions()
Examples
build_functions_df(fs = c("apple", "apply", "+"), title = "Test")
Checks if a character input is valid
Description
Checks if a character input is valid
Usage
check_character(name = NULL, value = NULL, allowed = NULL, nullok = FALSE)
Arguments
name |
Argument name. |
value |
Argument value. |
allowed |
Allowed argument values. |
nullok |
Logical for whether NULL values are OK (TRUE) or not (FALSE). |
Checks if a logical input is valid
Description
Checks if a logical input is valid
Usage
check_logical(name = NULL, value = NULL)
Arguments
name |
Argument name. |
value |
Argument value. |
Choose from available flashcard decks
Description
This function prints a list of flashcard decks to the console and let's the user choose one of the decks. By default, the function searches the flashr_decks repo. But other GitHub repos can be used.
To narrow the results, include text in the pattern
argument (for example,
choose_deck(pattern = "r4ds")
).
Usage
choose_deck(
pattern = NULL,
choice = NULL,
repo = "JeffreyRStevens/flashr_decks"
)
Arguments
pattern |
String pattern to search in list of decks. |
choice |
Integer value of choice from list of decks if you already know which deck you would like to use without listing again. |
repo |
GitHub username and repo for deck repository in the format of "username/repository". Default value is "JeffreyRStevens/flashr_decks". |
Value
Outputs a list of available built-in flashcard decks to the console, where the user can choose one of the decks to generate flashcards.
Note
This function requires internet connectivity as it checks GitHub repos for decks.
See Also
Other functions for finding decks:
list_decks()
Examples
## Not run:
# Choose from all available decks in default repository
choose_deck()
# Choose from decks including text matching pattern
choose_deck(pattern = "r4ds")
# Choose from decks from specific repository
choose_deck(repo = "JeffreyRStevens/flashr_decks")
## End(Not run)
Create deck from vector of functions
Description
The create_deck()
function generates a set of flashcards with randomly
ordered pairs of terms and descriptions from a vector of functions provided
by the user. The function outputs reveal.js presentation as an HTML file.
If running in RStudio, the flashcards are output to the viewer.
Otherwise, they are output to a web browser.
Usage
create_deck(
x,
title = NULL,
termsfirst = TRUE,
package = TRUE,
theme = "moon",
file = NULL,
random = TRUE,
fontsize = "default",
fontcolor = NULL,
linkcolor = NULL,
use_browser = FALSE
)
Arguments
x |
Name of pre-existing flashcard deck or path and name of CSV file containing terms and descriptions |
title |
Title provided for flashcard deck. Defaults to "Custom deck" if not provided. |
termsfirst |
Logical indicating whether to show terms first (TRUE) or descriptions first (FALSE) |
package |
Logical indicating whether to include package name in term |
theme |
Name of reveal.js theme to use for flashcards |
file |
Path and file name used to save flashcard deck locally (must save as HTML) |
random |
Logical indicating whether to randomize order of terms (TRUE) or use order from data frame |
fontsize |
Base font size for presentation. Acceptable values include "default" (500%), "large" (700%), and "small" (300%). Custom values can be set as percentages (e.g., "250%"). |
fontcolor |
Font color for non-link text. Can be R color name, HTML color name, or hex code. |
linkcolor |
Font color for link text. Can be R color name, HTML color name, or hex code. |
use_browser |
Logical indicating whether to show the presentation in the RStudio viewer when available (FALSE) or the system's default browser (TRUE) |
Value
An HTML file of terms and descriptions rendered in the RStudio viewer or web browser.
See Also
Other functions for creating decks:
flashcard()
Examples
# Display terms then descriptions
my_functions <- c("as_tibble()", "bind_rows()", "c()")
create_deck(x = my_functions)
# Customize the title
create_deck(x = my_functions, title = "My deck")
# Save the HTML version of the flashcard deck locally
create_deck(x = my_functions, title = "My deck", file = "my_deck.html")
Data types deck
Description
This flashcard deck includes terms associated with data types and structures.
Usage
data_types
Format
A data frame with 4 columns.
- term
reference term or function
- description
description or definition of term
- url
URL for function documentation
- package
package including function/argument
- title
title of deck
Extract code blocks from R Markdown or Quarto file
Description
To extract code blocks, apply extract_code()
to R Markdown or Quarto files
either locally or via a URL. This function returns a character vector where
each line of content from an R code block is an element of the vector. Code
block options are not returned—only the content of the block. Code blocks
from other languages/engines (e.g., Python) are not returned.
Usage
extract_code(file, empty = TRUE, comments = TRUE)
Arguments
file |
Character string of file name for text that includes code blocks. Can be local file or URL. |
empty |
Logical indicating whether to include empty lines ( |
comments |
Logical indicating whether to include comment lines starting
with |
Value
Returns character vector of individual lines of code.
Note
This function is adapted from one Yihui Xie posted at https://yihui.org/en/2023/01/func-call/.
See Also
Other functions for extracting code and functions:
build_functions_df()
,
extract_functions()
Examples
extract_code("https://raw.githubusercontent.com/JeffreyRStevens/flashr/refs/heads/main/README.Rmd")
Extract function calls from character vector of R code
Description
This function finds all of the R functions in a character vector of R code.
For R scripts, first use readLines()
or readr::read_file()
to import
the script into a character vector. For R Markdown or Quarto documents,
first use extract_code()
to find all of the R code in code blocks. The
character vector can then be passed to extract_functions()
to find all of
the functions. By default, all instances of functions are returned. To omit
duplicate functions, set duplicates = FALSE
.
Usage
extract_functions(code, duplicates = TRUE)
Arguments
code |
Object that contains R code. |
duplicates |
Logical indicating whether to include duplicates of functions or whether to remove duplicates (default is TRUE, which includes duplicates). |
Value
Returns character vector of function names without parentheses (e.g., it returns "library" rather than "library()") included in R code.
Note
This function is adapted from one Yihui Xie posted at https://yihui.org/en/2023/01/func-call/.
See Also
Other functions for extracting code and functions:
build_functions_df()
,
extract_code()
Examples
extract_functions(extract_code(
"https://raw.githubusercontent.com/JeffreyRStevens/flashr/refs/heads/main/README.Rmd"
))
Gracefully fail if internet connection is not available
Description
CRAN policies require that "Packages which use Internet resources should fail gracefully with an informative message if the resource is not available or has changed (and not give a check warning nor error)." This solution is adapted from kvasilopoulos' response at https://forum.posit.co/t/internet-resources-should-fail-gracefully/49199/11. This function is not exported.
Usage
fail_gracefully(remote_file, maxtime = 10)
Arguments
remote_file |
Remote file to be downloaded. |
maxtime |
Maximum time to check connection before timing out. |
Create flashcards
Description
The flashcard()
function generates a set of flashcards with randomly
ordered pairs of terms and descriptions from built-in flashcard decks.
The function outputs reveal.js presentation as an HTML file.
If running in RStudio, the flashcards are output to the viewer.
Otherwise, they are output to a web browser.
Usage
flashcard(
x,
termsfirst = TRUE,
package = TRUE,
theme = "moon",
file = NULL,
random = TRUE,
fontsize = "default",
fontcolor = NULL,
linkcolor = NULL,
use_browser = FALSE,
omit_na = TRUE
)
Arguments
x |
Name of pre-existing flashcard deck or path and name of CSV file containing terms and descriptions |
termsfirst |
Logical indicating whether to show terms first (TRUE) or descriptions first (FALSE) |
package |
Logical indicating whether to include package name in term |
theme |
Name of reveal.js theme to use for flashcards |
file |
Path and file name used to save flashcard deck locally (must save as HTML) |
random |
Logical indicating whether to randomize order of terms (TRUE) or use order from data frame |
fontsize |
Base font size for presentation. Acceptable values include "default" (500%), "large" (700%), and "small" (300%). Custom values can be set as percentages (e.g., "250%"). |
fontcolor |
Font color for non-link text. Can be R color name, HTML color name, or hex code. |
linkcolor |
Font color for link text. Can be R color name, HTML color name, or hex code. |
use_browser |
Logical indicating whether to show the presentation in the RStudio viewer when available (FALSE) or the system's default browser (TRUE) |
omit_na |
Logical indicating whether to omit terms that have no descriptions from the deck (default is TRUE, which omits terms with no descriptions) |
Value
An HTML file of terms and descriptions rendered in the RStudio viewer or web browser.
Note
This function requires internet connectivity to use existing decks. An internet connection is not required if you supply a CSV file. However, without an internect connection, themes other than black, white, and serif, may not render properly, as they require access to Google Fonts.
See Also
Other functions for creating decks:
create_deck()
Examples
# Display terms then descriptions
flashcard("data_types")
# Display descriptions then terms
flashcard("data_types", termsfirst = FALSE)
# Display terms without package information
flashcard("data_types", package = FALSE)
List available available flashcard decks
Description
This function searches for flashcard decks stored in GitHub repositories. By default, the function searches the flashr_decks repo. But other GitHub repos can be used.
To narrow the results, include text in the pattern
argument (for example,
list_decks(pattern = "r4ds")
).
Usage
list_decks(
pattern = NULL,
repo = "JeffreyRStevens/flashr_decks",
quiet = FALSE
)
Arguments
pattern |
String pattern to search in list of decks. |
repo |
GitHub username and repo for deck repository in the format of "username/repository". Default value is "JeffreyRStevens/flashr_decks". |
quiet |
Logical to prevent list information from printing to console. |
Details
You are welcome to fork the
flashr_decks repo and
modify or add your own decks. Or you can create your own repo from scratch.
Just make sure to place your decks in a directory called decks/
in your
root directory. Then set the repo
argument to your username and repo (see
Examples).
Value
Outputs a list of available built-in flashcard decks to the console.
See Also
Other functions for finding decks:
choose_deck()
Examples
# View all available decks
list_decks()
# View decks with text matching pattern
list_decks(pattern = "r4ds")
# View decks from specific repository
list_decks(repo = "JeffreyRStevens/flashr_decks")
Vectors deck
Description
This flashcard deck includes terms associated with vectors.
Usage
vectors
Format
A data frame with 4 columns.
- term
reference term or function
- description
description or definition of term
- package
package including function/argument
- title
title of deck