Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log2()<-, log10()<-, ilog2(), and ilog10() functions #52

Merged
merged 25 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
100473e
- Added `exp2(x)` and `exp10(x)`
nehill197 May 24, 2023
66f368e
Change examples
nehill197 May 25, 2023
fa5878f
Update documentation
nehill197 May 25, 2023
0719bad
- Added `log10()<-`, `log2()<-`, `ilog2()`, and `ilog10()`
nehill197 May 25, 2023
e5bafde
Change checks on x
nehill197 May 25, 2023
2c199b6
Add test case
nehill197 May 25, 2023
ba3db4e
Change descriptions; add examples
nehill197 May 25, 2023
eae1e50
Separate tests
nehill197 May 25, 2023
0319ee9
Just keep `chk_numeric()`
nehill197 May 25, 2023
6bf6eba
Change error messages; add test cases
nehill197 May 25, 2023
e2fc205
Merge changes from exp2-exp10 branch
nehill197 May 26, 2023
faab2c9
Tests for `log2()<-` and `log10()<-`
nehill197 May 26, 2023
0850dd0
Change documentation
nehill197 May 26, 2023
d3a6859
Add test case
nehill197 May 26, 2023
134476c
Merge with exp2-exp10 branch
nehill197 May 26, 2023
56d09b4
Tests for `log2()<-`, `log10()<-`, `ilog2()`, and `ilog10()`
nehill197 May 26, 2023
dfb1b4c
Remove checks; update tests
nehill197 May 26, 2023
4f9a0f8
Merge branch 'exp2-exp10' of github.com:poissonconsulting/extras into…
nehill197 May 26, 2023
4e1cb62
Update documentation
nehill197 May 26, 2023
9ae8897
Update examples and documentation
nehill197 May 26, 2023
f25691f
Update tests
nehill197 May 26, 2023
a31babd
Update documentation
nehill197 May 26, 2023
9dd42d6
Inherit params in documentation
nehill197 Jun 1, 2023
a528cf5
Separate edge case tests
nehill197 Jun 1, 2023
ac5440a
Separate and add descriptions to tests
nehill197 Jun 2, 2023
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
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ S3method(numericise,hms)
S3method(numericise,integer)
S3method(numericise,logical)
S3method(numericise,matrix)
export("log10<-")
export("log2<-")
export("log<-")
export("log_odds<-")
export("logit<-")
Expand All @@ -42,10 +44,14 @@ export(dev_norm)
export(dev_pois)
export(dev_pois_zi)
export(dev_student)
export(exp10)
export(exp2)
export(fabs)
export(fill_all)
export(fill_na)
export(ilog)
export(ilog10)
export(ilog2)
export(ilogit)
export(inv_logit)
export(inv_odds)
Expand Down
29 changes: 29 additions & 0 deletions R/exp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#' Exponential Transformation of Base 2
#'
#' Returns the transformation of 2^x.
#'
#' @param x An numeric atomic object.
#' @family translations
#' @return A numeric atomic object with the value of 2^x.
#' @export
#' @examples
#' x <- c(5, 10.5)
#' exp2(x)
exp2 <- function(x) {
2^x
}

#' Exponential Transformation of Base 10
#'
#' Returns the transformation of 10^x.
#'
#' @param x An numeric atomic object.
#' @family translations
#' @return A numeric atomic object with the value of 10^x.
#' @export
#' @examples
#' x <- c(5, 10.5)
#' exp10(x)
exp10 <- function(x) {
10^x
}
78 changes: 76 additions & 2 deletions R/log.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' @details A wrapper on [`exp`]`(value)`.
#'
#' @param x An existing R object.
#' @inheritParams params
#' @param value A numeric atomic object.
#' @family translations
#' @return Called for the side effect of updating `x`.
Expand All @@ -17,13 +17,51 @@
exp(value)
}

#' Log Base 2 Transformation
#'
#' Replaces a object with the base 2 exponent of value.
#'
#' @details A wrapper on [`exp2`]`(value)`.
#'
#' @inheritParams params
#' @param value A numeric atomic object.
#' @family translations
#' @return Called for the side effect of updating `x`.
#' @export
#' @examples
#' x <- NULL
#' log2(x) <- c(0.5, 5)
#' x
`log2<-` <- function(x, value) {
exp2(value)
}

#' Log Base 10 Transformation
#'
#' Replaces a object with the base 10 exponent of value.
#'
#' @details A wrapper on [`exp10`]`(value)`.
#'
#' @inheritParams params
#' @param value A numeric atomic object.
#' @family translations
#' @return Called for the side effect of updating `x`.
#' @export
#' @examples
#' x <- NULL
#' log10(x) <- c(0.5, 5)
#' x
`log10<-` <- function(x, value) {
exp10(value)
}

#' Inverse Log Transformation
#'
#' Inverse log transforms a numeric atomic object.
#'
#' @details A wrapper on [`exp`]`(value)`.
#'
#' @param x A numeric atomic object.
#' @inheritParams params
#' @family translations
#' @return A numeric atomic object.
#' @export
Expand All @@ -34,3 +72,39 @@
ilog <- function(x) {
exp(x)
}

#' Inverse Log Base 2 Transformation
#'
#' Inverse log transforms a numeric atomic object with base 2.
#'
#' @details A wrapper on [`exp2`]`(value)`.
#'
#' @inheritParams params
#' @family translations
#' @return A numeric atomic object.
#' @export
#' @examples
#' x <- c(2, 4.5)
#' ilog2(x)

ilog2 <- function(x) {
exp2(x)
}

#' Inverse Log Base 10 Transformation
#'
#' Inverse log transforms a numeric atomic object with base 10.
#'
#' @details A wrapper on [`exp10`]`(value)`.
#'
#' @inheritParams params
#' @family translations
#' @return A numeric atomic object.
#' @export
#' @examples
#' x <- c(2, 4.5)
#' ilog10(x)

ilog10 <- function(x) {
exp10(x)
}
6 changes: 6 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ reference:
desc: Conversion functions
contents:
- '`fabs`'
- '`exp2`'
- '`exp10`'
- '`ilog`'
- '`ilog2`'
- '`ilog10`'
- '`ilogit`'
- '`invlogit`'
- '`inv_odds`'
- '`log2<-`'
- '`log10<-`'
- '`logit`'
- '`odds`'
- '`phi`'
Expand Down
41 changes: 41 additions & 0 deletions man/exp10.Rd

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

41 changes: 41 additions & 0 deletions man/exp2.Rd

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

6 changes: 6 additions & 0 deletions man/fabs.Rd

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

8 changes: 7 additions & 1 deletion man/ilog.Rd

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

44 changes: 44 additions & 0 deletions man/ilog10.Rd

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

44 changes: 44 additions & 0 deletions man/ilog2.Rd

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

Loading