Skip to content

Commit

Permalink
updating docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroliman committed Feb 3, 2025
1 parent e1c029e commit fd6039b
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 22 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
release:
types: [published]
workflow_dispatch:

name: pkgdown.yaml

permissions: read-all

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
folder: docs
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Authors@R:
Description: Provides an R6-based encapsulated object-oriented programming
framework for simulation modeling studies in R.
License: GPL (>= 3)
URL: https://randcorporation.github.io/R6Sim/
Imports:
assertthat,
data.table,
Expand Down
16 changes: 14 additions & 2 deletions R/R6Experiment.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,22 @@
# Purpose: The R6Experiment contains one or more models...
#------------------------------------------------------------------------------#

#' R6 Class Representing a `R6Experiment`
#' R6 Class Representing an `R6Experiment`
#'
#' @description
#' This class implements a `R6Experiment`.
#' Manages experimental designs and execution for R6Sim models.
#'
#' @examples
#' model1 <- MyModel$new("baseline")
#' model2 <- MyModel$new("alternative")
#'
#' experiment <- R6Experiment$new(model1, model2)
#' experiment$set_parameter("growth_rate", "grid", values = c(0.01, 0.05))
#' experiment$set_parameter("noise", "lhs", min = 0, max = 1)
#' experiment$set_design(n_lhs = 50)
#' results <- experiment$run(n_cores = 4, parallel = TRUE)
#'
#' @export
#'
#' @import R6
#' @export
Expand Down
55 changes: 46 additions & 9 deletions R/R6Sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,42 @@
# Creation Date: August 2022
#------------------------------------------------------------------------------#

#' R6 Class Representing an `R6Sim` model
#' R6 Class for a Simulation Model
#'
#' @description
#' This class implements an `R6Sim` model
#' Base class for building simulation models with R6. Provides methods for managing inputs,
#' parameters, and simulation execution.
#'
#' @details
#' The R6Sim class includes functionality for:
#' * Input and parameter management
#' * JSON serialization
#' * Parallel execution
#' * Parameter sampling
#'
#' @examples
#' # Create simulation model
#' MyModel <- R6::R6Class(
#' "MyModel",
#' inherit = R6Sim,
#' public = list(
#' initialize = function(name) {
#' super$initialize(name)
#' self$set_input("population", 1000)
#' self$set_input("growth_rate", 0.05)
#' },
#' simulate = function(...) {
#' pop <- self$inputs$population
#' growth <- self$inputs$growth_rate
#' results <- pop * (1 + growth)^(1:10)
#' return(data.frame(year = 1:10, population = results))
#' }
#' )
#' )
#'
#' model <- MyModel$new("pop_model")
#' results <- model$simulate()
#'
#' @import R6
#' @export
R6Sim <- R6::R6Class(

Expand Down Expand Up @@ -76,14 +106,21 @@ R6Sim <- R6::R6Class(
#' @description
#' Set Input
#'
#' @param name Character string defining the input name
#' @param value Input value. Can be a single value, list or vector.
#' @param type Optional character string defining input type.
#'
#' @details
#' Use this function to add a new input to a R6Sim object.
#' Model inputs should be added or modified through this function. Inputs can be vectors or lists of strings, numeric or integers, to guarantee that they can be translated to and from JSON without any issues.
#' Validates input types and maintains input registry.
#' Accepts numeric, character, logical, data.frame and list inputs.
#' Type tags enable selective JSON export.
#'
#' @examples
#' model$set_input("population", 1000, type = "parameter")
#' model$set_input("growth_rates", c(0.01, 0.02), type = "scenario")
#' model$set_input("settings", list(iterations = 100), type = "config")
#'
#' @param name character string defining the input name
#' @param value input value. Can be a single value, a list or a vector.
#' @param description sentence describing the meaning of this input.
#' @param type optional character string defining the type of input. Useful when one wants to only write inputs of a certain type to json.
#' @export
set_input = function(name, value, type = NA_character_) {
R6Sim_set_input(self = self, name = name, value = value, type = type)
},
Expand Down
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
url: https://randcorporation.github.io/R6Sim/
template:
bootstrap: 5

15 changes: 13 additions & 2 deletions man/R6Experiment.Rd

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

7 changes: 7 additions & 0 deletions man/R6Sim-package.Rd

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

69 changes: 60 additions & 9 deletions man/R6Sim.Rd

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

0 comments on commit fd6039b

Please sign in to comment.