Skip to content

Commit

Permalink
Add mtcars_df2 demo dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-dray committed Nov 13, 2023
1 parent 094625e commit 662c53c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 45 deletions.
23 changes: 22 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#'
#' A modified version of the mtcars dataset prepared into a data.frame structure
#' ready for coercion to an a11ytables-class object with
#' \code{\link{as_a11ytable}}.
#' \code{\link{as_a11ytable}}. Uses a dataframe as input to the cover table;
#' \code{\link{mtcars_df}} uses a list as input to the cover table.
#'
#' @format A data frame with 5 rows and 7 columns:
#' \describe{
Expand All @@ -16,3 +17,23 @@
#'
#' @source \code{\link[datasets:mtcars]{mtcars}}
"mtcars_df"

#' Test Data: A Modified 'mtcars' Dataframe
#'
#' A modified version of the mtcars dataset prepared into a data.frame structure
#' ready for coercion to an a11ytables-class object with
#' \code{\link{as_a11ytable}}. Uses a list as input to the cover table;
#' \code{\link{mtcars_df}} uses a dataframe as input to the cover table.
#'
#' @format A data frame with 5 rows and 7 columns:
#' \describe{
#' \item{tab_title}{Character. Text to appear on the sheet's tab.}
#' \item{sheet_type}{Character. The content type for each sheet: 'cover', 'contents', 'notes', or 'tables'.}
#' \item{sheet_title}{Character. The title that will appear in the top-left of each sheet.}
#' \item{blank_cells}{Character. An explanation for any blank cells in the table.}
#' \item{source}{Character. The origin of the data, if relevant.}
#' \item{table}{List-column of data.frames (apart from the cover, which is a list) containing the statistical tables.}
#' }
#'
#' @source \code{\link[datasets:mtcars]{mtcars}}
"mtcars_df2"
85 changes: 42 additions & 43 deletions data-raw/data-mtcars.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file generates and writes the dataset 'mtcars_df'
# This file generates and writes the dataset 'mtcars_df' and 'mtcars_df2'

library(tibble)

Expand All @@ -11,6 +11,20 @@ cover_df <-
) |>
as.data.frame()

cover_list <-
list(
"Description" = c(
"Aspects of automobile design and performance from 'Motor Trend' in 1974.",
"Used by Henderson and Velleman in a 1981 paper in 'Biometrics'."
),
"Properties" = "Suppressed values are replaced with the value '[c]'.",
"Contact" = c(
"[Visit the website.](https://github.com/co-analysis/a11ytables)",
"[Email the team.](mailto:not-a-real-email-address@completely-fake.net)",
"Telephone 0123456789"
)
)

contents_df <-
tribble(
~"Sheet name", ~"Sheet title",
Expand All @@ -33,16 +47,9 @@ stats_df_1 <- mtcars |>
rownames_to_column("car") |>
subset(select = c("car", "cyl", "mpg"))

names(stats_df_1) <- c(
"Car",
"Cylinder count",
"Miles per gallon [note 1]"
)
names(stats_df_1) <- c("Car", "Cylinder count", "Miles per gallon [note 1]")

stats_df_1$Notes <- c(
rep("[note 2]", 2),
rep(NA_character_, 4)
)
stats_df_1$Notes <- c(rep("[note 2]", 2), rep(NA_character_, 4))

stats_df_1[3, 2:3] <- "[c]"

Expand All @@ -51,27 +58,32 @@ stats_df_2 <- mtcars |>
rownames_to_column("car") |>
subset(select = c("car", "hp", "drat"))

names(stats_df_2) <- c(
"Car",
"Gross horsepower",
"Rear axle ratio"
)
names(stats_df_2) <- c("Car", "Gross horsepower", "Rear axle ratio")

# Using cover_df as the table input for the cover
mtcars_df <- tibble(
tab_title = c(
"Cover",
"Contents",
tab_title = c("Cover", "Contents", "Notes", "Table_1", "Table_2"),
sheet_type = c("cover", "contents", "notes", "tables", "tables"),
sheet_title = c(
"The 'mtcars' Demo Dataset",
"Table of contents",
"Notes",
"Table_1",
"Table_2"
"Table 1: Car Road Tests 1",
"Table 2: Car Road Tests 2"
),
sheet_type = c(
"cover",
"contents",
"notes",
"tables",
"tables"
blank_cells = c(
rep(NA_character_, 3),
"A blank cell in the Notes column indicates that there is no note for that row.",
NA_character_
),
source = c(rep(NA_character_, 3), rep("Motor Trend (1974)", 2)),
table = list(cover_df, contents_df, notes_df, stats_df_1, stats_df_2)
)

# Using cover_list as the table input for the cover
mtcars_df2 <- tibble(
tab_title = c("Cover", "Contents", "Notes", "Table_1", "Table_2"),
sheet_type = c("cover", "contents", "notes", "tables", "tables"),
sheet_title = c(
"The 'mtcars' Demo Dataset",
"Table of contents",
Expand All @@ -80,27 +92,14 @@ mtcars_df <- tibble(
"Table 2: Car Road Tests 2"
),
blank_cells = c(
NA_character_,
NA_character_,
NA_character_,
rep(NA_character_, 3),
"A blank cell in the Notes column indicates that there is no note for that row.",
NA_character_
),
source = c(
NA_character_,
NA_character_,
NA_character_,
"Motor Trend (1974)",
"Motor Trend (1974)"
),
table = list(
cover_df,
contents_df,
notes_df,
stats_df_1,
stats_df_2
)
source = c(rep(NA_character_, 3), rep("Motor Trend (1974)", 2)),
table = list(cover_list, contents_df, notes_df, stats_df_1, stats_df_2)
)

# Write to data/
usethis::use_data(mtcars_df, overwrite = TRUE)
usethis::use_data(mtcars_df2, overwrite = TRUE)
Binary file added data/mtcars_df2.rda
Binary file not shown.
3 changes: 2 additions & 1 deletion man/mtcars_df.Rd

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

30 changes: 30 additions & 0 deletions man/mtcars_df2.Rd

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

0 comments on commit 662c53c

Please sign in to comment.