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
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
^renv$
^renv\.lock$
^\.RData
^\.Rhistory
^README*
Expand All @@ -14,3 +16,4 @@
^\.travis\.yml$
^\.git
^docs$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
55 changes: 55 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Adapted from https://github.com/r-lib/actions/tree/v2/examples
on:
push:
branches: [main, master]
pull_request:
workflow_dispatch:

name: R-CMD-check

permissions: read-all

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
# - {os: macos-latest, r: 'release'}
# - {os: windows-latest, r: 'release'}
# - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
# - {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

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

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual", "--compact-vignettes=gs+qpdf")'
87 changes: 87 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Adapted from https://github.com/r-lib/actions/tree/v2/examples
on:
push:
branches: [main, master]
pull_request:
workflow_dispatch:

name: test-coverage

permissions: read-all

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

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

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2, any::DT, any::htmltools
needs: coverage

- name: Test coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
print(cov)
covr::to_cobertura(cov)
covr::report(cov, file = "coverage-report.html", browse = FALSE)

# Per-file coverage table in the job summary
pct <- covr::percent_coverage(cov)
files <- covr::tally_coverage(cov, by = "line")
by_file <- aggregate(value ~ filename, data = files, FUN = function(v) mean(v > 0) * 100)
by_file <- by_file[order(by_file$value), ]
lines <- c(
sprintf("## Test coverage: %.2f%%", pct),
"",
"| File | Coverage |",
"|------|---------:|",
sprintf("| `%s` | %.2f%% |", by_file$filename, by_file$value)
)
summary_file <- Sys.getenv("GITHUB_STEP_SUMMARY")
if (nzchar(summary_file)) writeLines(lines, summary_file)
shell: Rscript {0}

- uses: codecov/codecov-action@v5
with:
# Fail if error only when a token is configured (e.g. not on forks)
fail_ci_if_error: ${{ secrets.CODECOV_TOKEN != '' }}
files: ./cobertura.xml
plugins: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
coverage-report.html
lib/
cobertura.xml
${{ runner.temp }}/package
if-no-files-found: ignore
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Suggests:
lme4,
magrittr,
rmarkdown,
testthat
testthat (>= 3.2.0),
withr
Description: A mixed collection of useful and semi-useful diverse
statistical functions, some of which may even be referenced in
The R Primer book. See Ekstrøm, C. T. (2016). The R Primer. 2nd edition. Chapman & Hall.
Expand All @@ -37,4 +38,5 @@ BugReports: https://github.com/ekstroem/MESS/issues
Encoding: UTF-8
ByteCompile: true
License: GPL-2
RoxygenNote: 7.3.3
Config/testthat/edition: 3
Config/roxygen2/version: 8.1.1
101 changes: 54 additions & 47 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -95,53 +95,60 @@ import(geepack)
import(ggformula)
import(ggplot2)
import(graphics)
importFrom(Rcpp,sourceCpp)
importFrom(clipr,write_clip)
importFrom(grDevices,col2rgb)
importFrom(grDevices,rgb)
importFrom(grDevices,
col2rgb,
rgb
)
importFrom(methods,as)
importFrom(stats,approx)
importFrom(stats,chisq.test)
importFrom(stats,coef)
importFrom(stats,complete.cases)
importFrom(stats,cor)
importFrom(stats,cor.test)
importFrom(stats,dbinom)
importFrom(stats,density)
importFrom(stats,dnorm)
importFrom(stats,drop.scope)
importFrom(stats,family)
importFrom(stats,formula)
importFrom(stats,gaussian)
importFrom(stats,glm)
importFrom(stats,integrate)
importFrom(stats,lm)
importFrom(stats,lm.fit)
importFrom(stats,model.frame)
importFrom(stats,model.matrix)
importFrom(stats,model.offset)
importFrom(stats,naprint)
importFrom(stats,p.adjust.methods)
importFrom(stats,pbinom)
importFrom(stats,pchisq)
importFrom(stats,pf)
importFrom(stats,pnorm)
importFrom(stats,predict)
importFrom(stats,qbinom)
importFrom(stats,qnorm)
importFrom(stats,rbinom)
importFrom(stats,rnorm)
importFrom(stats,rstandard)
importFrom(stats,rstudent)
importFrom(stats,sd)
importFrom(stats,simulate)
importFrom(stats,smooth.spline)
importFrom(stats,splinefun)
importFrom(stats,terms)
importFrom(stats,uniroot)
importFrom(stats,update)
importFrom(stats,update.formula)
importFrom(stats,xtabs)
importFrom(utils,capture.output)
importFrom(utils,head)
importFrom(utils,tail)
importFrom(stats,
approx,
chisq.test,
coef,
complete.cases,
cor,
cor.test,
dbinom,
density,
dnorm,
drop.scope,
family,
formula,
gaussian,
glm,
integrate,
lm,
lm.fit,
model.frame,
model.matrix,
model.offset,
naprint,
p.adjust.methods,
pbinom,
pchisq,
pf,
pnorm,
predict,
qbinom,
qnorm,
rbinom,
rnorm,
rstandard,
rstudent,
sd,
simulate,
smooth.spline,
splinefun,
terms,
uniroot,
update,
update.formula,
xtabs
)
importFrom(utils,
capture.output,
head,
tail
)
useDynLib(MESS)
1 change: 1 addition & 0 deletions R/MESS-package.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' @keywords internal
"_PACKAGE"

#' @importFrom Rcpp sourceCpp
## usethis namespace: start
#' @useDynLib MESS
## usethis namespace: end
Expand Down
5 changes: 3 additions & 2 deletions R/age.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ age <- function(from, to) {

age = to_lt$year - from_lt$year

age <- ifelse(to_lt$mon < from_lt$mon | (to_lt$mon == from_lt$mon & to_lt$mday < from_lt$mday), age - 1, age)

if (any(age<0))
stop("ages cannot be negative")

ifelse(to_lt$mon < from_lt$mon | (to_lt$mon == from_lt$mon & to_lt$mday < from_lt$mday), age - 1, age)
age
}

15 changes: 10 additions & 5 deletions R/auc.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ function(x, y, from = min(x, na.rm=TRUE), to = max(x, na.rm=TRUE), type=c("linea
if (length(unique(x)) < 2)
return(NA)

# sort X
o <- order(x)
x <- x[o]
y <- y[o]

if (type=="linear") {

## Default option
Expand All @@ -85,23 +90,23 @@ function(x, y, from = min(x, na.rm=TRUE), to = max(x, na.rm=TRUE), type=c("linea
# Get the order of the first occurrence of unique values in sorted x
# This works because the new points are added to the end of the vector
unique_order <- order(match(sort(unique(newx)), newx))

# Get the unique sorted x values
x_sorted_unique <- sort(unique(newx))

# Match the sorted unique x values to their first occurrence in x
match_indices <- match(x_sorted_unique, newx)

# Reorder y accordingly
y_sorted <- newy[match_indices]

newx <- x_sorted_unique
newy <- y_sorted

values <- approx(newx, newy, xout = sort(unique(c(from, to, newx[newx > from & newx < to]))), ...)
res <- 0.5 * sum(diff(values$x) * (abs(values$y[-1]) + abs(values$y[-length(values$y)])))
}

} else { ## If it is not a linear approximation
if (absolutearea)
myfunction <- function(z) { abs(splinefun(x, y, method="natural")(z)) }
Expand Down
Loading
Loading