RConversion
01 Syntax
02 Methods
| Name | Overloads | Summary |
|---|---|---|
| asDate2 | 1 | parse string text content as date time values |
| isDateTime | 1 | the given string is in datetime format? |
| asDate | 1 | parse string text content as date time values |
| asObject | 1 | Cast any .NET clr object to R# s4 class system object |
| unlist | 1 | Flatten Lists Given a list structure x, unlist simplifies it to produce a vector which contains all the atomic components which occur in x. |
| unlistOfRList | 1 | |
| asDataframe | 1 | Coerce to a Data Frame Functions to check if an object is a data frame, or coerce it if possible. |
| castListRowsToDataframe | 1 | cast row list data to a data table object. |
| castListMatrix | 1 | each item in listdata is a row? |
| castListToDataframe | 1 | cast column list to dataframe |
| asVector | 1 | Vectors vector produces a vector of the given length and mode. |
| asList | 1 | Lists – Generic and Dotted Pairs Functions to construct, coerce and check for both kinds of R lists. |
| asInteger | 1 | Cast the given vector or list to integer type |
| asDouble | 1 | Double-Precision Vectors Create, coerce to or test for a double-precision vector. |
| asNumeric | 1 | Numeric Vectors Creates or coerces objects of type "numeric". |
| asCharacters | 1 | Character Vectors Create or test for objects of type "character". |
| isCharacter | 1 | Character Vectors Create or test for objects of type "character". |
| isLogical | 1 | Logical Vectors Create or test for objects of type "logical", and the basic logical constants. |
| asRaw | 1 | cast any R# object to raw buffer |
| asPipeline | 1 | running pipeline function in linq pipeline mode |
| castType | 1 | try to cast type class of the given data sequence |
| asLogicals | 1 |
03 Members
Object, Environment)parse string text content as date time values
| Name | Type | Description |
|---|---|---|
obj | Object | - |
env | Environment | - |
String)the given string is in datetime format?
| Name | Type | Description |
|---|---|---|
str | String | - |
Object, Environment)parse string text content as date time values
| Name | Type | Description |
|---|---|---|
obj | Object | - |
env | Environment | - |
Object)Cast any .NET clr object to R# s4 class system object
| Name | Type | Description |
|---|---|---|
obj | Object | - |
Flatten Lists
Given a list structure x, unlist simplifies it to produce a vector which contains all the atomic components which occur in x.
unlist is generic: you can write methods to handle specific classes of objects, see InternalMethods, and note, e.g., relist with the unlist method for relistable objects.
If recursive = False, the Function will Not recurse beyond the first level items In x.
Factors are treated specially. If all non-list elements Of x are factors (Or ordered factors) Then the result will be a factor With levels the union Of the level sets Of the elements, In the order the levels occur In the level sets Of the elements (which means that If all the elements have the same level Set, that Is the level Set Of the result).
x can be an atomic vector, but Then unlist does Nothing useful, Not even drop names.
By Default, unlist tries to retain the naming information present in x. If use.names = FALSE all naming information Is dropped.
Where possible the list elements are coerced To a common mode during the unlisting, And so the result often ends up As a character vector. Vectors will be coerced To the highest type Of the components In the hierarchy NULL < raw < logical < Integer < Double < complex < character < list < expression: pairlists are treated As lists.
A list Is a (generic) vector, And the simplified vector might still be a list (And might be unchanged). Non-vector elements Of the list (For example language elements such As names, formulas And calls) are Not coerced, And so a list containing one Or more Of these remains a list. (The effect Of unlisting an lm fit Is a list which has individual residuals As components.) Note that unlist(x) now returns x unchanged also For non-vector x, instead Of signaling an Error In that Case.
| Name | Type | Description |
|---|---|---|
x | Object | an R Object, typically a list Or vector. |
[typeof] | Object | element type of the array |
env | Boolean | - |
NULL or an expression or a vector of an appropriate mode to hold the list components.
The output type Is determined from the highest type Of the components In the hierarchy NULL < raw < logical < Integer < Double < complex < character < list < expression, after coercion Of pairlists To lists.
Value(Of Boolean))| Name | Type | Description |
|---|---|---|
rlist | list | - |
Coerce to a Data Frame
Functions to check if an object is a data frame, or coerce it if possible.
| Name | Type | Description |
|---|---|---|
x | Object | any R object. |
env | Object | - |
IEnumerable(Of list), Environment)cast row list data to a data table object.
| Name | Type | Description |
|---|---|---|
rows | IEnumerable(Of list) | each elements list in this collection data is a row in the generated dataframe object. |
env | Environment | - |
each item in listdata is a row?
| Name | Type | Description |
|---|---|---|
rows | KeyValuePair(Of String, Object)() | - |
env | String() | - |
cast column list to dataframe
| Name | Type | Description |
|---|---|---|
listData | Dictionary(Of String, Object) | - |
env | list | - |
Vectors
vector produces a vector of the given length and mode.
as.vector, a generic, attempts to coerce its argument into a vector of mode mode (the default is to coerce to whichever vector mode is most convenient): if the result is atomic all attributes are removed.
The atomic modes are "logical", "integer", "numeric" (synonym "double"), "complex", "character" and "raw".
If mode = "any", Is.vector may Return True For the atomic modes, list And expression. For any mode, it will Return False If x has any attributes except names. (This Is incompatible With S.) On the other hand, As.vector removes all attributes including names For results Of atomic mode (but Not those Of mode "list" nor "expression").
Note that factors are Not vectors; Is.vector returns False And as.vector converts a factor To a character vector For mode = "any".
as.vector and is.vector are quite distinct from the meaning of the formal class "vector" in the methods package, and hence as(x, "vector") and is(x, "vector").
Note that as.vector(x) Is Not necessarily a null operation if is.vector(x) Is true: any names will be removed from an atomic vector.
Non-vector modes "symbol" (synonym "name") And "pairlist" are accepted but have long been undocumented: they are used To implement As.name And As.pairlist, And those functions should preferably be used directly. None Of the description here applies To those modes: see the help For the preferred forms.
| Name | Type | Description |
|---|---|---|
x | Object | an R object. |
mode | Object | character string naming an atomic mode or "list" or "expression" or (except for vector) "any". Currently, is.vector() allows any type (see typeof) for mode, and when mode is not "any", |
env | Environment | - |
For vector, a vector of the given length and mode. Logical vector elements are initialized to FALSE, numeric vector elements to 0, character vector elements to "", raw vector elements to nul bytes and list/expression elements to NULL.
For as.vector, a vector (atomic Or of type list Or expression). All attributes are removed from the result if it Is of an atomic mode, but Not in general for a list result. The default method handles 24 input types And 12 values of type: the details Of most coercions are undocumented And subject To change.
For Is.vector, TRUE Or FALSE. Is.vector(x, mode = "numeric") can be true for vectors of types "integer" Or "double" whereas is.vector(x, mode = "double") can only be true for those of type "double".
Lists – Generic and Dotted Pairs
Functions to construct, coerce and check for both kinds of R lists. Cast the raw dictionary object to R# list object
this function supports the generic function calls
Almost all lists in R internally are Generic Vectors, whereas traditional dotted pair lists (as in LISP) remain available but rarely seen by users (except as formals of functions).
The arguments To list Or pairlist are Of the form value Or tag = value. The functions Return a list Or dotted pair list composed Of its arguments With Each value either tagged Or untagged, depending On how the argument was specified.
alist handles its arguments as if they described function arguments. So the values are Not evaluated, And tagged arguments with no value are allowed whereas list simply ignores them. alist Is most often used in conjunction with formals.
as.list attempts to coerce its argument to a list. For functions, this returns the concatenation of the list of formal arguments And the function body. For expressions, the list of constituent elements Is returned. as.list Is generic, And as the default method calls as.vector(mode = "list") for a non-list, methods for as.vector may be invoked. as.list turns a factor into a list of one-element factors, keeping names. Other attributes may be dropped unless the argument already Is a list Or expression. (This Is inconsistent with functions such as as.character which always drop attributes, And Is for efficiency since lists can be expensive to copy.)
Is.list returns TRUE if And only if its argument Is a list Or a pairlist of length > 0>0. Is.pairlist returns TRUE if And only if the argument Is a pairlist Or NULL (see below).
The "environment" method for as.list copies the name-value pairs (for names Not beginning with a dot) from an environment to a named list. The user can request that all named objects are copied. Unless sorted = TRUE, the list Is in no particular order (the order depends on the order of creation of objects And whether the environment Is hashed). No enclosing environments are searched. (Objects copied are duplicated so this can be an expensive operation.) Note that there Is an inverse operation, the as.environment() method for list objects.
An empty pairlist, pairlist() Is the same As NULL. This Is different from list(): some but Not all operations will promote an empty pairlist To an empty list.
as.pairlist Is implemented as as.vector(x, "pairlist"), And hence will dispatch methods for the generic function as.vector. Lists are copied element-by-element into a pairlist And the names of the list used as tags for the pairlist the return value for other types of argument Is undocumented.
list, Is.list And Is.pairlist are primitive functions.
| Name | Type | Description |
|---|---|---|
x | Object | object to be coerced or tested. this function will make a data copy if the input data is already a list |
args | Object | for dataframe type:
|
Object, Environment)Cast the given vector or list to integer type
| Name | Type | Description |
|---|---|---|
x | Object | - |
Object, Environment)Double-Precision Vectors
Create, coerce to or test for a double-precision vector.
as.double is a generic function. It is identical to as.numeric. Methods should return an object of base type "double".
Double-precision values
All R platforms are required To work With values conforming To the IEC 60559 (also known As IEEE 754) standard. This basically works With a precision Of 53 bits, And represents To that precision a range Of absolute values from about 2E-308 To 2E+308. It also has special values NaN (many Of them), plus And minus infinity And plus And minus zero (although R acts As If these are the same). There are also denormal(ized) (Or subnormal) numbers With absolute values above Or below the range given above but represented To less precision.
See .Machine for precise information on these limits. Note that ultimately how double precision numbers are handled Is down to the CPU/FPU And compiler.
In IEEE 754-2008/IEC605592011 this Is called 'binary64’ format.
Note on names
It Is a historical anomaly that R has two names for its floating- point vectors, double And numeric (And formerly had real).
Double Is the name Of the type. numeric Is the name Of the mode And also Of the implicit Class. As an S4 formal Class, use "numeric".
The potential confusion Is that R has used mode "numeric" To mean 'double or integer’, which conflicts with the S4 usage. Thus is.numeric tests the mode, not the class, but as.numeric (which is identical to as.double) coerces to the class.
| Name | Type | Description |
|---|---|---|
x | Object | object to be coerced or tested. |
env | Environment | - |
as.double attempts to coerce its argument to be of double type: like as.vector it strips attributes including names. (To ensure that an object is of double type without stripping attributes, use storage.mode.) Character strings containing optional whitespace followed by either a decimal representation or a hexadecimal representation (starting with 0x or 0X) can be converted, as can special values such as "NA", "NaN", "Inf" and "infinity", irrespective of case.
Object, Environment)Numeric Vectors
Creates or coerces objects of type "numeric". is.numeric is a more general test of an object being interpretable as numbers.
NULL will be treated as ZERO based on the rule of VisualBasic runtime conversion, the as.numeric function makes an array value copy always.
| Name | Type | Description |
|---|---|---|
x | Object | object to be coerced or tested. |
env | Environment | - |
Character Vectors
Create or test for objects of type "character".
as.character and is.character are generic: you can write methods to handle specific classes of objects, see InternalMethods. Further, for as.character the default method calls as.vector, so dispatch is first on methods for as.character and then for methods for as.vector.
as.character represents real And complex numbers to 15 significant digits (technically the compiler's setting of the ISO C constant DBL_DIG, which will be 15 on machines supporting IEC60559 arithmetic according to the C99 standard). This ensures that all the digits in the result will be reliable (and not the result of representation error), but does mean that conversion to character and back to numeric may change the number. If you want to convert numbers to character with the maximum possible precision, use format.
| Name | Type | Description |
|---|---|---|
x | Object | object to be coerced or tested. |
args | list | the additional argument values for format values to string, example as |
env | Environment | - |
as.character attempts to coerce its argument to character type; like as.vector it strips attributes including names. For lists and pairlists (including language objects such as calls) it deparses the elements individually, except that it extracts the first element of length-one character vectors.
Object)Character Vectors
Create or test for objects of type "character".
| Name | Type | Description |
|---|---|---|
x | Object | object to be coerced or tested. |
is.character returns TRUE or FALSE depending on whether its argument is of character type or not.
Object)Logical Vectors
Create or test for objects of type "logical", and the basic logical constants.
| Name | Type | Description |
|---|---|---|
x | Object | Object To be coerced Or tested. |
cast any R# object to raw buffer
| Name | Type | Description |
|---|---|---|
obj | Object | numeric values or character vector |
env | Encodings | - |
A stream object that contains raw bytes data
Object, Environment)running pipeline function in linq pipeline mode
| Name | Type | Description |
|---|---|---|
seq | Object | any kind of object sequence in R# environment |
try to cast type class of the given data sequence
| Name | Type | Description |
|---|---|---|
any | Object | - |
type | String | - |
env | Environment | - |
Object, Environment)