asUnsigned | R Documentation |
This function is used as a check on numeric values (either numeric or integer vectors) to ensure that the values are all non-negative. This is used when we pass values from R to a native routine that expects unsigned integers or size_t, etc. types. This raises an error or a warning if it finds any element that is negative.
asUnsigned(value, type, force = FALSE)
value |
the numeric values |
type |
the name of the class to which to coerce the |
force |
a logical value. If |
The result of coercing val
to class specified by type
.
If any values are negative, the function raises either a warning or an error.
Duncan Temple Lang
coerce
The RGCCTranslationUnit package
x = c(0, 1, 2, 0, 1, 2) asUnsigned(x, "integer") asUnsigned(c(-1, x), "integer", force = TRUE) try(asUnsigned(c(-1, x), "integer", force = FALSE)) setClass("truncatedUnsignedInt", contains = "integer") setValidity("truncatedUnsignedInt", function(obj) if(!all(obj >= 0)) "some values are negative" else TRUE) setAs("numeric", "truncatedUnsignedInt", function(from) { if(any(from < 0)) from[from < 0 ] = 0L new("truncatedUnsignedInt", from) }) asUnsigned(c(-1, x), "truncatedUnsignedInt", force = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.