Skip to content

Commit

Permalink
Add documentation to S3 class
Browse files Browse the repository at this point in the history
  • Loading branch information
Selbosh committed Dec 2, 2021
1 parent 70b3999 commit cba9500
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CRAN-RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This package was submitted to CRAN on 2021-12-01.
Once it is accepted, delete this file and tag the release (commit a88ce56).
This package was submitted to CRAN on 2021-12-02.
Once it is accepted, delete this file and tag the release (commit 42b16b0).
14 changes: 14 additions & 0 deletions R/index0.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#' Normally R is indexed from 1, but with the special `index0` class, you can
#' have vectors that are indexed from zero. Works both for subsetting (extraction)
#' and (sub-)assignment.
#' An `index0` object is just like a normal vector or matrix, but `x[i]` returns
#' or replaces the `(i+1)`th index.
#'
#' Assign the class `index0` to a vector, using `as.index0()` or `index_from_0()`,
#' then use the subset operators normally and they will be indexed from zero.
Expand All @@ -29,6 +31,18 @@
#' m[0, 1]
#' m[0, 1] <- 99
#' m
#'
#' @return
#' `as.index0` returns the input (typically a vector or matrix) unchanged except
#' for the addition of an `index0` class attribute, which enables the zero-based
#' indexing behaviour. Use `as.index1` to remove this class again, if present.
#'
#' If `x` is a zero-indexed object with class `index0`, then `x[i]` returns an
#' appropriate subset of `x`. The returned subset is also zero-indexed.
#' `x[i] <- value` changes the `i`th element (effectively `(i+1)`th element in
#' ordinary R code) in place.
#'
#' `is.index0(x)` returns `TRUE` if `x` is indexed from zero, otherwise `FALSE`.
#'
#' @source
#' Partially inspired by this Stack Overflow answer:
Expand Down
3 changes: 2 additions & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

0 errors | 0 warnings | 1 note

* This is a new release.
* This is (a resubmission of) a new release.
* Details have been added to `\value` for the S3 class
14 changes: 14 additions & 0 deletions man/index0.Rd

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

0 comments on commit cba9500

Please # to comment.