The mutatomic class is a mutable version of atomic classes.
It works exactly the same in all aspects as regular atomic classes.
There is only one real difference:
Pass-by-reference functions in 'squarebrackets'
only accept atomic objects when they are of class mutatomic,
for greater safety.
In all other aspects, mutatomic objects are the same as R's regular atomic objects,
including the behaviour of the [<- operator .
Exposed functions (beside the S3 methods):
Usage
mutatomic(data, names = NULL, dim = NULL, dimnames = NULL)
as.mutatomic(x, ...)
is.mutatomic(x)
couldb.mutatomic(x)Value
For mutatomic(), as.mutatomic():
Returns a mutatomic object.
For is.mutatomic():
Returns TRUE if the object is mutatomic,
and returns FALSE otherwise.
For couldb.mutatomic():
Returns TRUE if the object is one of the following types:
logical, integer, double, character, complex, raw.
Returns FALSE otherwise.
Note
Always use
the exported functions given by 'squarebrackets'
to create a mutatomic object,
as they make necessary safety checks.
Examples
x <- mutatomic(
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
#> mutatomic
#> typeof: integer
x <- matrix(1:10, ncol = 2)
x <- as.mutatomic(x)
is.mutatomic(x)
#> [1] TRUE
print(x)
#> [,1] [,2]
#> [1,] 1 6
#> [2,] 2 7
#> [3,] 3 8
#> [4,] 4 9
#> [5,] 5 10
#> mutatomic
#> typeof: integer
x[, 1]
#> [1] 1 2 3 4 5
#> mutatomic
#> 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
#> mutatomic
#> typeof: double
is.mutatomic(x)
#> [1] TRUE