rvcompatibility {rv} | R Documentation |
Sets the compatibility level of the rv package;
if you experience an unexplained error while
the rv
package is loaded,
try rvcompatibility(1)
and re-run your program.
rvcompatibility(level=NULL)
level |
0, 1, or NULL . 0 or 1 sets the compatibility level; NULL causes the function to return the current level. |
'rv' implements (loosely) a replacement for the standard numeric and logical classes.
A numeric or logical vector is just a special case of the more general random vector data type (same would apply for the complex data type but this isn't implemented).
To implement the package right, we need certain functions to work completely with
random vectors and basically `fool' R into believing that the rv
objects are
just as good as the standard R data types.
For example, is.atomic
should return TRUE
for rv
objects,
and c(1, rvnorm(1))
should dispatch the c.rv
method.
This is not possible, unfortunately, without replacing some of the "primitive" generic and non-generic functions.
If everything were generic, we could re-define what 'numeric' means for example.
This isn't possible (for obvious efficiency
and compatibility reasons) so we need to do some surgery, replacing
standard functions with special ones that check whether a given argument is
an rv object or not, and then choose the right function to work on the arguments
(a primitive kind of a method dispatch mechanism).
For examples see is.atomic
, c
, var
(for which we have implemented a generic replacement.)
Unfortunately even this may not make rv fully compatible. Thus we need a system to undo a function replacement.
The only use of this function - currently - is rvcompatibility(1)
which restores all functions in the base backage. Example: `c(...)
'.
Inserting numeric/logical objects into an rv objects still works, but inserting an rv object into a plain numeric/logical vector will not work, for example.
NOTE. When the package rv is detached (you can do it simply with detachrv()
),
all functions that were replaced upon attaching the package are immediately restored.
If level
is NULL
, the current compatibility level.
If level
is 0 or 1, returns the previous compatibility level.
## Not run: rvcompatibility(0) x <- 1:9 # Will work since rv checks that the value to be injected is an rv: x[1] <- rvnorm(1) print(x) ## Not run: rvcompatibility(1) x <- 1:9 # Will fail since R thinks this is assigning a list into a vector component: x[1] <- rvnorm(1) print(class(x)) # "list" ## End(Not run) # However, this works: x <- as.rv(1:9) rvcompatibility(1) x[1] <- rvnorm(1) rvcompatibility(0) # restore the fully rv-enabled computing environment... ## End(Not run)