Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ _quarto/*
!_quarto/_freeze/
*.docx
*.knit.md
tests/testthat/_snaps/
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ Language: en-US
Depends:
R (>= 4.1.0)
Imports:
cli,
stats
Suggests:
altdoc,
foodwebr,
knitr,
rmarkdown,
spelling,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(calculate_summary)
export(example_function)
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# rpt (development version)

* Added package structure visualization article using foodwebr to demonstrate function dependencies and call graphs
* Created layered helper function architecture for realistic foodwebr demonstrations
* Added `calculate_summary()` function for computing summary statistics

* Switched from pkgdown to altdoc for documentation generation. Now using Quarto Website for documentation with native math equation support via MathJax.
* Removed pkgdown-specific configurations and workflows.
* Retained RevealJS multi-format support for Quarto vignettes and articles.
Expand Down
13 changes: 13 additions & 0 deletions R/calculate_statistic.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' Calculate Statistic
#'
#' Internal helper function to calculate a statistical measure on cleaned data.
#'
#' @param x A numeric vector
#'
#' @return The median value
#' @keywords internal
#' @noRd
calculate_statistic <- function(x) {
x_clean <- clean_data(x)
stats::median(x_clean)
}
21 changes: 21 additions & 0 deletions R/calculate_summary.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' Calculate Summary Statistics
#'
#' Calculate multiple summary statistics for a numeric vector.
#'
#' @param x A numeric vector
#'
#' @return A named list with mean, median, and standard deviation
#' @export
#'
#' @examples
#' calculate_summary(c(1, 2, 3, 4, 5))
#' calculate_summary(c(1, NA, 3, 4, 5))
calculate_summary <- function(x) {
x_clean <- clean_data(x)

list(
mean = format_result(mean(x_clean)),
median = example_function(x),
sd = format_result(stats::sd(x_clean))
)
}
14 changes: 14 additions & 0 deletions R/clean_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#' Clean Data
#'
#' Internal helper function to clean data by removing NA values and preparing
#' for analysis.
#'
#' @param x A numeric vector
#'
#' @return A cleaned numeric vector with NA values removed
#' @keywords internal
#' @noRd
clean_data <- function(x) {
validate_input(x)
x[!is.na(x)]
}
7 changes: 5 additions & 2 deletions R/example_function.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#' Example Function
#'
#' This is an example function that demonstrates basic functionality.
#' It validates, cleans, calculates statistics, and formats the result.
#'
#' @param x A numeric vector
#'
#' @return The median of the input vector
#' @return The median of the input vector, rounded to 2 decimal places
#' @export
#'
#' @examples
#' example_function(c(1, 2, 3, 4, 5))
#' example_function(c(1, NA, 3, 4, 5))
example_function <- function(x) {
stats::median(x)
result <- calculate_statistic(x)
format_result(result)
}
12 changes: 12 additions & 0 deletions R/format_result.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Format Result
#'
#' Internal helper function to format the result for output.
#'
#' @param result A numeric value
#'
#' @return A formatted numeric value (rounded to 2 decimal places)
#' @keywords internal
#' @noRd
format_result <- function(result) {
round(result, digits = 2)
}
21 changes: 21 additions & 0 deletions R/validate_input.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' Validate Input Data
#'
#' Internal helper function to validate input data for statistical calculations.
#'
#' @param x A numeric vector
#'
#' @return TRUE if valid, throws error otherwise
#' @keywords internal
#' @noRd
validate_input <- function(x) {
if (!is.numeric(x)) {
cli::cli_abort("Input must be numeric", call = NULL)
}
if (length(x) == 0) {
cli::cli_abort("Input must have at least one element", call = NULL)
}
if (all(is.na(x))) {
cli::cli_abort("Input cannot be all NA values", call = NULL)
}
TRUE
}
3 changes: 3 additions & 0 deletions altdoc/quarto_website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ website:
file: vignettes/quarto_vignette.qmd
- text: "Advanced"
file: vignettes/articles/quarto_article.qmd
- text: "Package Structure"
file: vignettes/articles/package-structure.qmd
sidebar:
collapse-level: 1
contents:
Expand All @@ -48,6 +50,7 @@ website:
- section: Advanced
contents:
- vignettes/articles/quarto_article.qmd
- vignettes/articles/package-structure.qmd
- section: $ALTDOC_MAN_BLOCK
style: floating
- text: News
Expand Down
8 changes: 8 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ CMD
Callouts
CodeFactor
Codecov
DiagrammeR
DOCX
Lifecycle
MathJax
README
RevealJS
Shortcode
Slidebreak
Expand All @@ -14,9 +16,14 @@ altdoc
callout
callouts
cdot
codebases
emplate
foldable
foodweb
foodwebr
formatter
frac
graphviz
frontmatter
linter
lintr
Expand All @@ -26,3 +33,4 @@ serodynamics
shortcode
slidebreak
tabset
tidygraph
21 changes: 21 additions & 0 deletions man/calculate_summary.Rd

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

4 changes: 3 additions & 1 deletion man/example_function.Rd

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

27 changes: 27 additions & 0 deletions tests/testthat/test-calculate_summary.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
test_that("calculate_summary works", {
result <- calculate_summary(c(1, 2, 3, 4, 5))
expect_type(result, "list")
expect_named(result, c("mean", "median", "sd"))
expect_equal(result$mean, 3)
expect_equal(result$median, 3)
expect_equal(result$sd, 1.58)
})

test_that("calculate_summary handles NA values", {
result <- calculate_summary(c(1, NA, 3, 4, 5))
expect_type(result, "list")
expect_equal(result$median, 3.5)
expect_equal(result$mean, 3.25)
})

test_that("calculate_summary handles errors", {
expect_error(calculate_summary(character()), "Input must be numeric")
expect_error(
calculate_summary(numeric()),
"Input must have at least one element"
)
expect_error(
calculate_summary(c(NA_real_, NA_real_, NA_real_)),
"Input cannot be all NA values"
)
})
14 changes: 14 additions & 0 deletions tests/testthat/test-example_function.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
test_that("example_function works", {
expect_equal(example_function(c(1, 2, 3)), 2)
expect_equal(example_function(c(1, 2, 3, 4, 5)), 3)
expect_equal(example_function(c(1, NA, 3, 4, 5)), 3.5)
expect_equal(example_function(c(1.111, 2.222, 3.333)), 2.22)
})

test_that("example_function handles errors", {
expect_error(example_function(character()), "Input must be numeric")
expect_error(
example_function(numeric()),
"Input must have at least one element"
)
expect_error(
example_function(c(NA_real_, NA_real_, NA_real_)),
"Input cannot be all NA values"
)
})
Loading