Skip to content

Commit

Permalink
Updating website and various minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-phelps committed Apr 12, 2024
1 parent ffababe commit af70e56
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 87 deletions.
17 changes: 10 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ Package: chefStats
Title: Provide methods for different statistics
Version: 0.1.1
Authors@R:
c(person(given = "MEWP (Matthew Phelps)",
c(person(given = "Matthew David Phelps",
role = "aut",
email = "mewp@novonordisk.com"),
person(given = "NOSJ (Nicolai Skov Johnsen)",
person(given = "Nicolai Skov Johnsen",
role = "aut",
email = "nosj@novonordisk.com"),
person(given = "ABIU (Anders Bilgrau)",
person(given = "Anders Bilgrau",
role = "aut",
email = "abiu@novonordisk.com"),
person(given = "SCQY (scqy)",
person(given = "Simon Clancy",
role = "aut",
email = "scqy@novonordisk.com"),
person(given = "CINO (Christian Haargaard Olsen)",
person(given = "Christian Haargaard Olsen",
role = c("aut", "cre"),
email = "cino@novonordisk.com"),
person(given = "Novo Nordisk A/S",
Expand All @@ -25,7 +25,8 @@ License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Suggests:
Suggests:
testr,
covr,
pkgdown,
testthat,
Expand All @@ -45,10 +46,12 @@ Imports:
cli,
usethis
Remotes:
hta-pharma/chef
hta-pharma/chef,
matthew-phelps/testr
Config/testthat/edition: 3
VignetteBuilder: knitr
Config/testthat/parallel: true
URL:
https://hta-pharma.github.io/chefStats/,
https://github.com/hta-pharma/chefStats,
https://app.codecov.io/github/hta-pharma/chefStats
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export(mean_value)
export(n_event)
export(n_event_)
export(n_event_100y)
export(n_sub_)
export(n_subj)
export(n_subj_)
export(n_subj_event)
export(n_subj_event_)
export(obs_time_by_trt)
Expand Down
4 changes: 2 additions & 2 deletions R/building_blocks.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @return An integer
#' @export
#'
n_sub_ <-
n_subj_ <-
function(dat,
cell_index,
subjectid_var) {
Expand Down Expand Up @@ -72,7 +72,7 @@ p_subj_event_ <-
cell_index,
intersect_index,
subjectid_var) {
n_sub <- n_sub_(dat, cell_index = cell_index,subjectid_var = subjectid_var)
n_sub <- n_subj_(dat, cell_index = cell_index,subjectid_var = subjectid_var)

# If there are no subjects, no need for further calculations
if (n_sub == 0) {
Expand Down
6 changes: 2 additions & 4 deletions R/by_strata_by_trt.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ n_subj <- function(dat,
subjectid_var,
...) {
stat <-
n_sub_(dat = dat,
n_subj_(dat = dat,
cell_index = cell_index,
subjectid_var = subjectid_var)

Expand Down Expand Up @@ -176,16 +176,14 @@ p_subj_event <-
#' @param ... Optional parameters.
#' @return a data.table containing all statistical outputs
#' @export
#'
#' @examples
count_set <- function(dat,
event_index,
cell_index,
subjectid_var,
...) {
intersect_index <- intersect(event_index, cell_index)
n_subjects <-
n_sub_(dat = dat,
n_subj_(dat = dat,
cell_index = cell_index,
subjectid_var = subjectid_var)
n_events <- n_event_(dat = dat, intersect_index = intersect_index)
Expand Down
43 changes: 42 additions & 1 deletion R/use_chefStats.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ use_chefStats <-
"stat_across_strata_across_trt"
),
file_name = NULL) {
check_use_chefStats_inputs(fn_name)
type <- match.arg(fn_type)
fn_path <-
normalizePath(file.path("R", paste0(fn_name, ".R")), mustWork = FALSE)
file.path("R", paste0(fn_name, ".R"))
switch(
type,
stat_by_strata_by_trt = usethis::use_template(
Expand Down Expand Up @@ -48,3 +49,43 @@ use_chefStats <-
)

}

error_no_dir <- function(dir){
if (!dir.exists(dir)) {
stop(paste0("Directory ", dir, " does not exist"))
}
}

extract_function_names <- function(dir) {
x <- list.files(dir, full.names = TRUE, pattern = "*.[Rr]")
fn_names_ls <- lapply(x, function(i) {
lang_objs <- Filter(is.language, parse(i))
fun_entries <-
Filter(function(x) {
grepl(", function", toString(x))
}, lang_objs)
sapply(fun_entries, function(fun_entry_i) {
trimws(strsplit(toString(fun_entry_i), ",")[[1]][2])
})
})
unlist(fn_names_ls)
}
error_function_already_exists <- function(new_fn_name, existing_fn_names){
fn_exists <- any(new_fn_name == existing_fn_names)
if (!fn_exists) {
return(invisible(TRUE))
}
msg <- paste0(
"The function name `",
new_fn_name,
"` already exists. Please choose another name"
)
stop(msg,call. = FALSE)
}

check_use_chefStats_inputs <- function(new_fn_name, dir = "R/"){
error_no_dir(dir)
existing_fn_names <- extract_function_names(dir)
error_function_already_exists(new_fn_name, existing_fn_names)
return(invisible(TRUE))
}
27 changes: 19 additions & 8 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,30 @@ output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->
# chefStats <a href="https://hta-pharma.github.io/chefStats/"><img src="man/figures/logo.png" align="right" height="138" alt="chefStats website" /></a>

# A library of statistical methods for chef-style AMNOG analyses <a href="https://hta-pharma.github.io/chefStats/"><img src="man/figures/logo.png" align="right" height="138" alt="chefStats website" /></a>
A library of statistical methods for chef-style AMNOG analyses

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Aim

The {chefStats} package aims to provide a library of fast, validated methods for use in AMNOG analysis created by the chef package.

As the functions found in chefStats are designed to be used with chef, it may be unwieldy to use these functions independently.
As the functions found in chefStats are designed to be used with [chef](https://hta-pharma.github.io/chef) in the context of the [ramnog](https://hta-pharma.github.io/ramnog) framework, it may be unwieldy to use these functions independently.


# Installation

The package is available to install from GitHub:

```{r, eval=FALSE}
remotes::install_github("hta-pharma/chefStats")
```


# How to contribute

For information on how to contribute, please refer to [ramnog contributing documentation](https://hta-pharma.github.io/ramnog/articles/dev_contribute).

# Developer Documentation
# More information

Please refer to {ramnog} for general developer documentation.
[Ramnog Developer Documentation](https://hta-pharma.github.io/ramnog/articles/#:~:text=Debugging-,Development,-Git%20Workflow)
These site focuses on the functions of chefStats. For more context on how these functions should be utilized to produce an AMNOG-like analysis, please see the [ramnog](https://hta-pharma.github.io/ramnog) documentation.
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# A library of statistical methods for chef-style AMNOG analyses <a href="https://hta-pharma.github.io/chefStats/"><img src="man/figures/logo.png" align="right" height="138" alt="chefStats website" /></a>
# chefStats <a href="https://hta-pharma.github.io/chefStats/"><img src="man/figures/logo.png" align="right" height="138" alt="chefStats website" /></a>

A library of statistical methods for chef-style AMNOG analyses

# Aim

The {chefStats} package aims to provide a library of fast, validated
methods for use in AMNOG analysis created by the chef package.

As the functions found in chefStats are designed to be used with chef,
it may be unwieldy to use these functions independently.
As the functions found in chefStats are designed to be used with
[chef](https://hta-pharma.github.io/chef) in the context of the
[ramnog](https://hta-pharma.github.io/ramnog) framework, it may be
unwieldy to use these functions independently.

# Installation

The package is available to install from GitHub:

``` r
remotes::install_github("hta-pharma/chefStats")
```

# How to contribute

For information on how to contribute, please refer to [ramnog
contributing
documentation](https://hta-pharma.github.io/ramnog/articles/dev_contribute).

# Developer Documentation
# More information

Please refer to {ramnog} for general developer documentation. [Ramnog
Developer
Documentation](https://hta-pharma.github.io/ramnog/articles/#:~:text=Debugging-,Development,-Git%20Workflow)
These site focuses on the functions of chefStats. For more context on
how these functions should be utilized to produce an AMNOG-like
analysis, please see the [ramnog](https://hta-pharma.github.io/ramnog)
documentation.
9 changes: 8 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
url: https://hta-pharma.github.io/chefStats/
template:
bootstrap: 5
bootswatch: flatly

navbar:
structure:
left: [intro, articles, reference, news]
right: [github]

reference:
- title: By strata and treatment level
desc: |
Expand Down Expand Up @@ -31,7 +38,7 @@ reference:
- barnard_test_
- make_two_by_two_by_k_
- make_two_by_two_
- n_sub_
- n_subj_
- n_event_
- n_subj_event_
- p_subj_event_
Expand Down
6 changes: 1 addition & 5 deletions inst/templates/template-stat_by_strata_by_trt.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#' @export
#'
#' @examples
{
{
fn_name
}
} <- function(dat,
{{fn_name}} <- function(dat,
event_index,
cell_index,
strata_var,
Expand Down
6 changes: 3 additions & 3 deletions man/n_sub_.Rd → man/n_subj_.Rd

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

35 changes: 6 additions & 29 deletions pkgdown/extra.css
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
.navbar-inverse {
background-color: #033572;
.dropdown-header {
font-size: 1.2rem;
color: #494646;
font-weight: 700;
}
.navbar-inverse .navbar-brand {
color: #BDB5AB;
}
.navbar-inverse .navbar-nav>li>a {
color: #BDB5AB;
}
.navbar-inverse .navbar-nav>.active>a {
background-color: #033572;
}
.navbar-inverse .navbar-nav>.active:hover>a {
background-color: #0069B4;
}
.list-group-item.active {
background-color: #033572;
border-color: #033572;
}
item.active, .list-group-item.active:hover {
background-color: #0069B4;
border-color: #0069B4;
}


.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
.text-muted {
color: #8f9c9d !important;
}
6 changes: 6 additions & 0 deletions tests/testthat/test-use_chefStats.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test_that("use_chefStats errors when given function name that already exists", {
testr::create_local_project()
dump("n_subj", file = "R/test.R")
expect_error(use_chefStats(fn_name = "n_subj",fn_type = "stat_by_strata_by_trt"),regexp = "The function name")

})
Loading

0 comments on commit af70e56

Please sign in to comment.