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

Allow assignment into an xpose_data object while maintaining the class #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# xpose 0.4.4.9000
### General
* Assignment into an "xpose_data" object now keeps the class of "xpose_data" instead of reverting to "uneval" (@billdenney #134)

# xpose 0.4.4
### General
* Improved documentation for `xpose_data` (@billdenney #99)
Expand Down
13 changes: 13 additions & 0 deletions R/xpdb_edits.R
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,16 @@ irep <- function(x, quiet = FALSE) {
msg(c('irep: ', max(x), ' simulations found.'), quiet)
x
}

#' Allow assignment into xpose_data without conversion to class uneval
#' @param x object from which to extract element(s) or in which to replace element(s).
#' @param i index specifying element to replace.
#' @param value typically an array-like R object of a similar class as x.
#' @return The object with the value replaced.
#' @noRd
`[[<-.xpose_data` <- function(x, i, value) {
x <- unclass(x)
x[[i]] <- value
as.xpdb(x)
}
`$<-.xpose_data` <- `[[<-.xpose_data`
8 changes: 0 additions & 8 deletions R/xpose_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,3 @@ xpose_data <- function(runno = NULL,
manual_import = manual_import)) %>%
structure(class = c('xpose_data', 'uneval'))
}

# Allow assignment into xpose_data without conversion to class uneval
# `[[<-.xpose_data` <- function(x, i, value) {
# x <- unclass(x)
# x[[i]] <- value
# as.xpdb(x)
# }
# `$<-.xpose_data` <- `[[<-.xpose_data`
11 changes: 11 additions & 0 deletions tests/testthat/test-xpdb_edits.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
context("test xpdb_edits")

test_that('Allow assignment within object while maintaining the class', {
xpdb_dollar <- xpdb_ex_pk
xpdb_dollar$options$quiet <- TRUE
expect_equal(class(xpdb_dollar), class(xpdb_ex_pk))

xpdb_bracket <- xpdb_ex_pk
xpdb_bracket[["options"]]$quiet <- TRUE
expect_equal(class(xpdb_bracket), class(xpdb_ex_pk))
})