Description Usage Format Details Fields Getters/setters Public methods Author(s) References Examples
TODO
1 |
1 2 | Class 'R6ClassGenerator' <environment: 0x0000000009bc83a0>
- attr(*, "name")= chr "Data_generator"
|
TODO
data
ANY
Actual data
r_format
IDataFormat
Instance of a class that implements the IDataFormat
interface and that contains meta format information for R.
ext_format
IDataFormat
Instance of a class that implements the IDataFormat
interface and that contains meta format information for external data
location.
order
ANY
Data order information (rows and columns currently).
See superclass
IData
See interface
IData
Janko Thyson janko.thyson@rappster.de
http://github.com/rappster/datar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | # Example data ------------------------------------------------------------
data_r <- data.frame(
x_1 = seq(10, 20, 5),
x_2 = seq(as.POSIXct("2015-01-01"), length.out = 3, by = "1 days"),
x_3 = TRUE,
stringsAsFactors = FALSE
)
data_ext <- data.frame(
x.1 = seq(10, 20, 5),
x.2 = as.character(seq(as.POSIXlt("2015-01-01"), length.out = 3, by = "1 days")),
x.3 = TRUE,
stringsAsFactors = FALSE
)
# Example meta format -----------------------------------------------------
r_format <- DataFormat$new(
format = list(
function(x, pattern = "\\d{4}-\\d{2}-\\d{2}") {
tmp <- lapply(x, function(ii) {
if (any(grepl(pattern, ii))) {
as.POSIXlt(ii)
} else {
ii
}
})
as.data.frame(tmp, stringsAsFactors = FALSE)
},
function(x) {
names(x) <- gsub("\\.", "_", names(x))
x
}
)
)
ext_format <- DataFormat$new(
format = list(
function(x, pattern = "\\d{4}-\\d{2}-\\d{2}") {
tmp <- lapply(x, function(ii) {
if (any(grepl(pattern, ii))) {
as.character(ii)
} else {
ii
}
})
as.data.frame(tmp, stringsAsFactors = FALSE)
},
function(x) {
names(x) <- gsub("_", ".", names(x))
x
}
)
)
# Apply R format ---------------------------------------------------------
inst <- Data$new(data = data_ext, r_format = r_format)
data_before <- inst$getData()
inst$applyRFormat()
data_after <- inst$getData()
## Names comparison //
names(data_before)
names(data_after)
## Class comparison //
sapply(data_before, class)
sapply(data_after, class)
# Apply external format ---------------------------------------------------
Data$undebug("applyExternalFormat")
inst <- Data$new(data = data_r, ext_format = ext_format)
data_before <- inst$getData()
inst$applyExternalFormat()
data_after <- inst$getData()
## Names comparison //
names(data_before)
names(data_after)
## Class comparison //
sapply(data_before, class)
sapply(data_after, class)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.