The mutable_atomic
class is a mutable version of atomic classes.
It works exactly the same in all aspects as regular atomic classes,
with only one real difference:
The 'squarebrackets' methods and functions that perform modification by reference
(basically all methods and functions with "set" in the name)
accept mutable_atomic
,
but do not accept regular atomic
.
See squarebrackets_PassByReference for details.
Like data.table
, [<-
performs R's default copy-on-modification semantics.
For modification by reference, use sb_set.
Exposed functions (beside the S3 methods):
mutable_atomic()
: create amutable_atomic
object from given data.couldb.mutable_atomic()
: checks if an object could becomemutable_atomic
.
An objects can becomemutable_atomic
if it is one of the following types:
logical, integer, double, character, complex, raw.bit64::
integer64 type is also supported, since it is internally defined as double.typecast.mutable_atomic()
type-casts and possibly reshapes a (mutable) atomic object, and returns amutable_atomic
object.
Does not preserve dimension names if dimensions are changed.
Usage
mutable_atomic(data, names = NULL, dim = NULL, dimnames = NULL)
as.mutable_atomic(x, ...)
# S3 method for default
as.mutable_atomic(x, ...)
is.mutable_atomic(x)
couldb.mutable_atomic(x)
typecast.mutable_atomic(x, type = typeof(x), dims = dim(x))
# S3 method for mutable_atomic
c(..., use.names = TRUE)
# S3 method for mutable_atomic
[(x, ...)
# S3 method for mutable_atomic
[(x, ...) <- value
# S3 method for mutable_atomic
format(x, ...)
# S3 method for mutable_atomic
print(x, ...)
Arguments
- data
atomic vector giving data to fill the
mutable_atomic
object.- names, dim, dimnames
- x
an atomic object.
- ...
method dependent arguments.
- type
a string giving the type; see typeof.
- dims
integer vector, giving the new dimensions.
- use.names
Boolean, indicating if names should be preserved.
- value
see Extract.
Value
For mutable_atomic()
, as.mutable_atomic()
, typecast.mutable_atomic()
:
Returns a mutable_atomic
object.
For is.mutable_atomic()
:
Returns TRUE
if the object is mutable_atomic
,
and returns FALSE
otherwise.
For couldb.mutable_atomic()
:
Returns TRUE
if the object is one of the following types:
logical, integer, double, character, complex, raw.
bit64::
integer64 type is also supported,
since it is internally defined as double.
Returns FALSE
otherwise.
Warning
Always use
the exported functions given by 'squarebrackets'
to create a mutable_atomic
object,
as they make necessary checks.
Circumventing these checks may break things!
Examples
x <- mutable_atomic(
1:20, dim = c(5, 4), dimnames = list(letters[1:5], letters[1:4])
)
x
#> a b c d
#> a 1 6 11 16
#> b 2 7 12 17
#> c 3 8 13 18
#> d 4 9 14 19
#> e 5 10 15 20
#> mutable_atomic
#> typeof: integer
typecast.mutable_atomic(x, "character")
#> [,1] [,2] [,3] [,4]
#> [1,] "1" "6" "11" "16"
#> [2,] "2" "7" "12" "17"
#> [3,] "3" "8" "13" "18"
#> [4,] "4" "9" "14" "19"
#> [5,] "5" "10" "15" "20"
#> mutable_atomic
#> typeof: character
x <- matrix(1:10, ncol = 2)
x <- as.mutable_atomic(x)
is.mutable_atomic(x)
#> [1] TRUE
print(x)
#> [,1] [,2]
#> [1,] 1 6
#> [2,] 2 7
#> [3,] 3 8
#> [4,] 4 9
#> [5,] 5 10
#> mutable_atomic
#> typeof: integer
x[, 1]
#> [1] 1 2 3 4 5
#> mutable_atomic
#> typeof: integer
x[] <- as.double(x)
#> coercing type from `integer` to `double`
print(x)
#> [,1] [,2]
#> [1,] 1 6
#> [2,] 2 7
#> [3,] 3 8
#> [4,] 4 9
#> [5,] 5 10
#> mutable_atomic
#> typeof: double
is.mutable_atomic(x)
#> [1] TRUE