native: 5 functions analysed · 1 typed · 2 untypeable · 1 timed out · 0 entry points (0 typed) · R: 313 definitions, 40 typed strict, 223 gradual, prelude debt 117 · fuzzing: 40 definitions, 1 unsound, 28 accept calls outside their domain · tyr dc7f1a7 · Rsem 5c142d7 · NativeSem 770a1eb · rstt 2b2696f unpinned
No .Call/.C/.Fortran/.External site in the R code, so no entry point.
static void SymbolShortcuts(void)
{
zoo_symbol_index = install("index");
zoo_symbol_oclass = install("oclass");
zoo_symbol_frequency = install("frequency");
zoo_symbol_timeDate_format = install("format");
zoo_symbol_timeDate_Data = install("Data");
zoo_symbol_timeDate_FinCenter = install("FinCenter");
}name: R_RegisterCCallable
void R_init_zoo(DllInfo *info)
{
SymbolShortcuts();
R_registerRoutines(info,
NULL,
callMethods,
NULL,
NULL);
R_useDynamicSymbols(info, FALSE);
#define RegisterZoo(routine) R_RegisterCCallable("zoo",#routine,(DL_FUNC) &routine)
/* used by external packages linking to internal xts code from C */
R_RegisterCCallable("zoo","zoo_lag",(DL_FUNC) &zoo_lag);
R_RegisterCCallable("zoo","zoo_coredata",(DL_FUNC) &zoo_coredata);
}function: [c_int] --> c(0..) argument: [c_int_na]
SEXP zoo_lag (SEXP x, SEXP _k, SEXP _pad)
{
#ifdef ZOO_DEBUG
Rprintf("zoo_lag\n");
#endif
SEXP result;
R_xlen_t i,j;
int k = asInteger(_k) * -1; /* -1 is zoo convention */
R_xlen_t nr = nrows(x);
R_xlen_t nc = ncols(x);
int P=0;
int PAD = asInteger(_pad);
R_xlen_t k_abs = abs(k); /* magnitude of the lag */
R_xlen_t k_src = (k > 0) ? 0 : k_abs; /* offset into x, "nrr stride" units */
R_xlen_t k_dst = (k > 0 && PAD) ? k_abs : 0; /* offset into result */
R_xlen_t k_pad = (k > 0) ? 0 : (nr - k_abs); /* where NA/pad values start */
if(k_abs > nr)
error("abs(k) must be less than nrow(x)");
PROTECT(result = allocVector(TYPEOF(x),
xlength(x) - (PAD ? 0 : abs(k)*nc))); P++;
R_xlen_t nrr;
if(xlength(result) > 0)
nrr = (R_xlen_t)(xlength(result)/nc);
else /* handle zero-length objects */
nrr = nr - (PAD ? 0 : k_abs);
R_xlen_t n_copy = nr - k_abs;
switch (TYPEOF(x)) {
case REALSXP:
for (j = 0; j < nc; j++) {
if (PAD) {
for (i = 0; i < k_abs; i++) {
REAL(result)[k_pad+i+(j*nrr)] = NA_REAL;
}
}
memcpy(&REAL(result)[k_dst+(j*nrr)], &REAL(x)[k_src+(j*nr)], sizeof(double) * n_copy);
}
break;
case INTSXP:
for (j = 0; j < nc; j++) {
if (PAD) {
for (i = 0; i < k_abs; i++) {
INTEGER(result)[k_pad+i+(j*nrr)] = NA_INTEGER;
}
}
memcpy(&INTEGER(result)[k_dst+(j*nrr)], &INTEGER(x)[k_src+(j*nr)], sizeof(int) * n_copy);
}
break;
case LGLSXP:
for (j = 0; j < nc; j++) {
if (PAD) {
for (i = 0; i < k_abs; i++) {
LOGICAL(result)[k_pad+i+(j*nrr)] = NA_LOGICAL;
}
}
memcpy(&LOGICAL(result)[k_dst+(j*nrr)], &LOGICAL(x)[k_src+(j*nr)], sizeof(int) * n_copy);
}
break;
case CPLXSXP:
for (j = 0; j < nc; j++) {
if (PAD) {
for (i = 0; i < k_abs; i++) {
COMPLEX(result)[k_pad+i+(j*nrr)].r = NA_REAL;
COMPLEX(result)[k_pad+i+(j*nrr)].i = NA_REAL;
}
}
memcpy(&COMPLEX(result)[k_dst+(j*nrr)], &COMPLEX(x)[k_src+(j*nr)], sizeof(Rcomplex) * n_copy);
}
break;
case RAWSXP:
for(j = 0; j < nc; j++) {
if (PAD) {
for (i = 0; i < k_abs; i++) {
RAW(result)[k_pad+i+(j*nrr)] = (Rbyte)0;
}
}
memcpy(&RAW(result)[k_dst+(j*nrr)], &RAW(x)[k_src+(j*nr)], sizeof(Rbyte) * n_copy);
}
break;
case STRSXP:
for(j = 0; j < nc; j++) {
if (PAD) {
for (i = 0; i < k_abs; i++) {
SET_STRING_ELT(result, k_pad+i+(j*nrr), NA_STRING);
}
}
for(i = 0; i < n_copy; i++) {
SET_STRING_ELT(result, k_dst+i+(j*nrr), STRING_ELT(x, k_src+i+(j*nr)));
}
}
break;
default:
error("unsupported type");
break;
}
copyMostAttrib(x, result); /* copy all attr *exept* names, dim, dimnames */
if(!PAD) {
/* need to shorten the index because the result was not padded with NA */
SEXP idx_x = PROTECT(getAttrib(x, zoo_symbol_index)); P++;
SEXP idx_data = idx_x;
if (isS4(idx_x)) {
/* should make this
1) generic for any S4 object if possible
2) test for timeDate as this is important
*/
SEXP idx_class = PROTECT(getAttrib(idx_x, R_ClassSymbol)); P++;
if (STRING_ELT(idx_class, 0) != mkChar("timeDate"))
error("'S4' objects must be of class 'timeDate'");
idx_data = PROTECT(GET_SLOT(idx_x, zoo_symbol_timeDate_Data)); P++;
}
int idx_type = TYPEOF(idx_data);
SEXP newindex = PROTECT(allocVector(idx_type, nrr)); P++;
R_xlen_t k_idx = (k > 0) ? k_abs : 0;
switch (idx_type) {
case REALSXP:
memcpy(REAL(newindex), &REAL(idx_data)[k_idx], nrr * sizeof(double));
break;
case INTSXP:
memcpy(INTEGER(newindex), &INTEGER(idx_data)[k_idx], nrr * sizeof(int));
break;
default:
error("unsupported index type");
break;
}
if (isS4(idx_x)) {
SEXP class = PROTECT(MAKE_CLASS("timeDate")); P++;
SEXP timeDate = PROTECT(NEW_OBJECT(class)); P++;
copyMostAttrib(idx_data, newindex);
SET_SLOT(timeDate, zoo_symbol_timeDate_Data,newindex);
SEXP format = PROTECT(GET_SLOT(idx_x, zoo_symbol_timeDate_format)); P++;
SET_SLOT(timeDate, zoo_symbol_timeDate_format, format);
SEXP finCenter = PROTECT(GET_SLOT(idx_x, zoo_symbol_timeDate_FinCenter)); P++;
SET_SLOT(timeDate, zoo_symbol_timeDate_FinCenter, finCenter);
setAttrib(result, zoo_symbol_index, timeDate);
} else {
copyMostAttrib(idx_data, newindex);
setAttrib(result, zoo_symbol_index, newindex);
}
}
/* reset dims */
if(!isNull(getAttrib(x, R_DimSymbol))) {
SEXP dims;
PROTECT(dims = allocVector(INTSXP, 2)); P++;
INTEGER(dims)[0] = nrr;
INTEGER(dims)[1] = nc;
setAttrib(result, R_DimSymbol, dims);
setAttrib(result, R_DimNamesSymbol, getAttrib(x, R_DimNamesSymbol));
}
UNPROTECT(P);
return result;
}name: zoo_lag
SEXP zoo_lagts (SEXP x, SEXP _k, SEXP _pad) {
int k_pos = asInteger(_k)*-1; /* change zoo default negative handling */
SEXP k = PROTECT(ScalarInteger(k_pos));
SEXP ans = zoo_lag (x, k, _pad);
UNPROTECT(1);
return ans;
}SEXP zoo_coredata (SEXP x, SEXP copyAttr)
{
/* copyAttr is a LGLSXP flag to indicate whether all
attributes are to be left intact. This provides
compatability with xts, by stripping all attributes
if desired, without the overhead or adding then
removing
*/
SEXP result;
R_xlen_t i, j, ncs, nrs;
int P=0;
PROTECT(result = allocVector(TYPEOF(x), xlength(x))); P++;
switch( TYPEOF(x)) {
case REALSXP:
memcpy(REAL(result), REAL(x), xlength(result) * sizeof(double));
break;
case INTSXP:
memcpy(INTEGER(result), INTEGER(x), xlength(result) * sizeof(int));
break;
case LGLSXP:
memcpy(LOGICAL(result), LOGICAL(x), xlength(result) * sizeof(int));
break;
case CPLXSXP:
memcpy(COMPLEX(result), COMPLEX(x), xlength(result) * sizeof(Rcomplex));
break;
case STRSXP:
ncs = ncols(x); nrs = nrows(x);
for(j=0; j< ncs; j++)
for(i=0; i< nrs; i++)
SET_STRING_ELT(result, i+j*nrs, STRING_ELT(x, i+j*nrs));
break;
case RAWSXP:
memcpy(RAW(result), RAW(x), xlength(result) * sizeof(unsigned char));
break;
default:
error("currently unsupported data type");
break;
}
if( !isNull(getAttrib(x, R_DimSymbol))) {
setAttrib(result, R_DimSymbol, getAttrib(x, R_DimSymbol));
if( !isNull(getAttrib(x, R_DimNamesSymbol)) ) {
setAttrib(result, R_DimNamesSymbol, getAttrib(x,R_DimNamesSymbol));
}
} else {
setAttrib(result, R_NamesSymbol, getAttrib(x, R_NamesSymbol));
}
if( asLogical(copyAttr)) {
copyMostAttrib(x,result);
SEXP oclass = PROTECT(getAttrib(x, zoo_symbol_oclass)); P++;
setAttrib(result, R_ClassSymbol, oclass);
}
setAttrib(result, zoo_symbol_index, R_NilValue);
setAttrib(result, zoo_symbol_oclass, R_NilValue);
setAttrib(result, zoo_symbol_frequency, R_NilValue);
UNPROTECT(P);
return result;
}| parameter | change | call | returned |
|---|---|---|---|
| origin | kind:null | as.Date.numeric(NA, "origin" = NULL, "fuzz_dot1" = new.env()) | (DBL & ~vec1)<Date> with { } |
| call | verdict | error |
|---|---|---|
| as.Date.numeric("x" = raw(0), "origin" = logical(0), "fuzz_dot1" = function(...) quote(f(x))) | error_type | base::+: non-numeric argument to binary operator |
| as.Date.numeric(NA, "origin" = as.raw(c(0)), "fuzz_dot1" = new.env()) | error_type | base::as.Date.default: do not know how to convert 'x' to class “Date” |
| as.Date.numeric(logical(0), 2147483647L, function(...) list(local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }))) | error_type | base::as.Date.default: do not know how to convert 'x' to class “Date” |
as.Date.numeric <- function (x, origin, ...) {
if (missing(origin)) origin <- "1970-01-01"
if (identical(origin, "0000-00-00")) origin <- as.Date("0000-01-01", ...) - 1
as.Date(origin, ...) + x
}is.object — a name the prelude does not declarename: is.object
as.Date <- function (x, ...) {
## for plain numeric input, call zoo:::as.Date.numeric
if (!is.object(x) && is.numeric(x)) as.Date.numeric(x, ...)
else UseMethod("as.Date")
}| parameter | change | call | returned |
|---|---|---|---|
| x | kind:null | .as_Date_default("x" = NULL, "fuzz_dot1" = new.env()) | (DBL & ~vec1)<Date> with { } |
| x | kind:null | .as_Date_default(NULL) | (DBL & ~vec1)<Date> with { } |
| call | verdict | error |
|---|---|---|
| .as_Date_default("a") | error_type | ::charToDate: character string is not in a standard unambiguous format |
| .as_Date_default("x" = NA_complex_) | error_type | base::as.Date.default: do not know how to convert 'x' to class “Date” |
| .as_Date_default("NA", NULL, local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), "fuzz_dot1" = as.name("x")) | error_type | base::strptime: invalid 'format' argument |
| .as_Date_default("x" = as.raw(c(255)), "fuzz_dot1" = NA_character_, "fuzz_dot2" = as.name("x")) | error_type | base::as.Date.default: do not know how to convert 'x' to class “Date” |
| .as_Date_default("x" = complex(0), "fuzz_dot1" = function(...) function(...) list(), "fuzz_dot2" = quote(f(x))) | error_type | base::as.Date.default: do not know how to convert 'x' to class “Date” |
.as_Date_default <- function(x, ...) base::as.Date(x, ...)UseMethod — a name the prelude does not declarename: UseMethod
MATCH <- function(x, table, nomatch = NA, ...)
UseMethod("MATCH")is.atomic — a name the prelude does not declarename: is.atomic
MATCH.default <- function(x, table, nomatch = NA, ...) {
if(is.atomic(x) && !is.object(x)) {
if(inherits(table, "Date")) {
x <- unclass(as.Date(x, origin = "1970-01-01"))
table <- unclass(table)
} else if(inherits(table, "POSIXt")) {
x <- unclass(as.POSIXct(x, origin = "1970-01-01"))
table <- unclass(as.POSIXct(table))
}
}
match(x, table, nomatch = nomatch, ...)
}match — a name the prelude does not declarename: match
MATCH.timeDate <- function(x, table, nomatch = NA, ...) {
match(as.POSIXct(x), as.POSIXct(table), nomatch = nomatch, ...)
}match — a name the prelude does not declarename: match
MATCH.times <- function(x, table, nomatch = NA, units = "sec", eps = 1e-10, ...) {
match(trunc(x, units, eps), trunc(table, units, eps), nomatch = nomatch, ...)
}as.Date — one of the package’s own names, itself untypedname: as.Date
MATCH.Date <- function(x, table, nomatch = NA, ...) {
if(!inherits(table, "Date")) table <- as.Date(table)
match(unclass(x), unclass(table), nomatch = nomatch, ...)
}match — a name the prelude does not declarename: match
MATCH.POSIXct <- function(x, table, nomatch = NA, ...) {
if(!inherits(table, "POSIXct")) table <- as.POSIXct(table)
match(unclass(x), unclass(table), nomatch = nomatch, ...)
}match — a name the prelude does not declarename: match
MATCH.POSIXlt <- function(x, table, nomatch = NA, ...) {
x <- as.POSIXct(x)
if(!inherits(table, "POSIXct")) table <- as.POSIXct(table)
match(unclass(x), unclass(table), nomatch = nomatch, ...)
}UseMethod — a name the prelude does not declarename: UseMethod
ORDER <- function(x, ...)
UseMethod("ORDER")Failure("Unsupported argument after an ellipsis.")ORDER.default <- function(x, ..., na.last = TRUE, decreasing = FALSE)
order(x, ..., na.last = na.last, decreasing = decreasing)order — a name the prelude does not declarename: order
ORDER.timeDate <- function(x, ...) {
order(as.POSIXct(x), ...)
}order — a name the prelude does not declarename: order
ORDER.chron <- ORDER.dates <- ORDER.times <- function(x, ...) {
order(as.numeric(x), ...)
}UseMethod — a name the prelude does not declarename: UseMethod
coredata <- function(x, ...)
UseMethod("coredata")((x: 'x, ...: any) -> 'x)<>coredata.default <- function(x, ...) xattr<- — a name the prelude does not declarename: attr<-
coredata.zoo <- function(x, ...)
{
attr(x, "class") <- attr(x, "oclass")
attr(x, "index") <- attr(x, "oclass") <- attr(x, "frequency") <- NULL
return(x)
}attr<- — a name the prelude does not declarename: attr<-
coredata.ts <- function(x, ...)
{
x <- unclass(x)
attr(x, "tsp") <- NULL
return(x)
}((x: { value: 'I1399, any }, ...: any) -> 'I1399)<>| parameter | change | call | returned |
|---|---|---|---|
| x | drop | coredata.irts(NULL, as.name("x")) | null |
| x | kind:null | coredata.irts("x" = NULL, "fuzz_dot1" = as.name("x")) | null |
coredata.irts <- function(x, ...)
{
return(x$value)
}@ — a name the prelude does not declarename: @
coredata.its <- function(x, ...)
{
return(x@.Data)
}UseMethod — a name the prelude does not declarename: UseMethod
"coredata<-" <- function(x, value)
{
UseMethod("coredata<-")
}is.vector — a name the prelude does not declarename: is.vector
"coredata<-.zoo" <- function(x, value)
{
stopifnot(length(x) == length(value))
if(!(is.vector(value) || is.factor(value) || is.matrix(value) || is.data.frame(value)))
stop(paste(dQuote("value"), ": attempt to assign invalid coredata to zoo object"))
if(is.matrix(value) || is.data.frame(value)) value <- as.matrix(value)
x[] <- value
attr(x, "oclass") <- attr(value, "class")
return(x)
}(((x: v('I1596)<`I121> with { dim: absent, any } | v('I1596)<`I121> with { dim: null, any }, value: v('I1596)) -> v('I1596)<`I121>) & ((x: v('I1597)<`I121> with { dim: dbl, any }, value: v('I1597)) -> v('I1597)<`I121>))<>| parameter | change | call | returned |
|---|---|---|---|
| x | wrap | coredata<-.ts(list(integer(0)), 2L) | { 2L<> with { } }<> with { } |
| x | wrap | coredata<-.ts("x" = list(structure(c(2147483647, -1), "dim" = c(2L, 1L))), "value" = 1000000) | { 1000000.<> with { } }<> with { } |
| call | verdict | error |
|---|---|---|
| coredata<-.ts(NA_character_, c("NA", "", NA_character_, "a", "")) | error_pkg | zoo::coredata<-.ts: length(x) == length(value) is not TRUE |
| coredata<-.ts(structure(character(0), "dim" = c(0L, 1L)), "value" = "NA") | error_pkg | zoo::coredata<-.ts: length(x) == length(value) is not TRUE |
| coredata<-.ts("x" = structure(as.raw(c(255)), "dim" = c(1L, 1L)), "value" = as.raw(c(0, 0))) | error_pkg | zoo::coredata<-.ts: length(x) == length(value) is not TRUE |
| coredata<-.ts(integer(0), 2L) | error_pkg | zoo::coredata<-.ts: length(x) == length(value) is not TRUE |
| coredata<-.ts("x" = structure(0, "dim" = c(1L, 1L)), "value" = c(Inf, 2)) | error_pkg | zoo::coredata<-.ts: length(x) == length(value) is not TRUE |
| coredata<-.ts("x" = logical(0), "value" = c(FALSE, TRUE, FALSE, FALSE, FALSE)) | error_pkg | zoo::coredata<-.ts: length(x) == length(value) is not TRUE |
"coredata<-.ts" <- function(x, value)
{
stopifnot(length(x) == length(value))
dim(value) <- dim(x)
x[] <- value
return(x)
}(((x: { value: v('I1645)<`I129> with { dim: absent, any } | v('I1645)<`I129> with { dim: null, any }, `I131 }<`I130>, value: v('I1645)) -> { value: v('I1645)<`I129>, `I131 }<`I130>) & ((x: { value: v('I1646)<`I129> with { dim: dbl, any }, `I131 }<`I130>, value: v('I1646)) -> { value: v('I1646)<`I129>, `I131 }<`I130>))<>| call | verdict | error |
|---|---|---|
| coredata<-.irts("x" = list("value" = TRUE, -1, as.name("x")), "value" = c(TRUE, NA)) | error_pkg | zoo::coredata<-.irts: length(x$value) == length(value) is not TRUE |
| coredata<-.irts(list("value" = structure(as.raw(c(255, 0)), "dim" = c(2L, 1L)), as.raw(c(0)), c("", "a", "", "a", "é")), "value" = raw(0)) | error_pkg | zoo::coredata<-.irts: length(x$value) == length(value) is not TRUE |
| coredata<-.irts("x" = list("value" = as.raw(c(0, 255, 255, 255, 0))), "value" = as.raw(c(255))) | error_pkg | zoo::coredata<-.irts: length(x$value) == length(value) is not TRUE |
| coredata<-.irts("x" = list("value" = c(NA, NA, NA, FALSE, FALSE)), "value" = logical(0)) | error_pkg | zoo::coredata<-.irts: length(x$value) == length(value) is not TRUE |
| coredata<-.irts("x" = list("value" = c(2L, -2147483647L, -1L, 2147483647L, -1L), list(-2147483647L)), "value" = c(-1L, 2147483647L)) | error_pkg | zoo::coredata<-.irts: length(x$value) == length(value) is not TRUE |
| coredata<-.irts(list("value" = structure(raw(0), "dim" = c(0L, 1L))), as.raw(c(255, 255, 255, 0, 0))) | error_pkg | zoo::coredata<-.irts: length(x$value) == length(value) is not TRUE |
"coredata<-.irts" <- function(x, value)
{
stopifnot(length(x$value) == length(value))
dim(value) <- dim(x$value)
x$value[] <- value
return(x)
}@ — a name the prelude does not declarename: @
"coredata<-.its" <- function(x, value)
{
stopifnot(length(x@.Data) == length(value))
dim(value) <- dim(x@.Data)
x@.Data[] <- as.matrix(value)
return(x)
}UseMethod — a name the prelude does not declarename: UseMethod
index <- function(x, ...)
{
UseMethod("index")
}NROW — a name the prelude does not declarename: NROW
index.default <- function(x, ...)
{
seq_len(NROW(x))
}((x: any with { index: 'I1706, any }, ...: any) -> 'I1706)<>| parameter | change | call | returned |
|---|---|---|---|
| x | attr:drop:index | index.zoo("x" = function(...) list(), "fuzz_dot1" = as.raw(c(255)), "fuzz_dot2" = 2L) | null |
| x | kind:list | index.zoo(list(), "fuzz_dot1" = new.env()) | null |
| x | kind:sym | index.zoo(as.name("x"), NULL) | null |
| x | wrap | index.zoo(list(structure(new.env(), "index" = c(complex(real = 0, imaginary = 0), NA_complex_))), character(0), local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), "fuzz_dot1" = NULL) | null |
| x | wrap | index.zoo(list(structure(as.raw(c(0, 255)), "index" = as.raw(c(255)))), as.raw(c(0, 255, 255, 0, 255))) | null |
| x | wrap | index.zoo(list(structure(new.env(), "index" = -1)), function(...) NULL, "fuzz_dot1" = NULL, "fuzz_dot2" = as.name("x")) | null |
index.zoo <- function(x, ...)
{
attr(x, "index")
}tsp — a name the prelude does not declarename: tsp
index.ts <- function(x, ...)
{
xtsp <- tsp(x)
seq(xtsp[1], xtsp[2], by = 1/xtsp[3])
}index — one of the package’s own names, itself untypedname: index
time.zoo <- function(x, ...)
{
index(x)
}UseMethod — a name the prelude does not declarename: UseMethod
"index<-" <- function(x, value)
{
UseMethod("index<-")
}UseMethod — a name the prelude does not declarename: UseMethod
"time<-" <- function(x, value)
{
UseMethod("time<-")
}index — one of the package’s own names, itself untypedname: index
"index<-.zoo" <- function(x, value)
{
if(length(index(x)) != length(value))
stop("length of index vectors does not match")
if(is.unsorted(ORDER(value)))
stop("new index needs to be sorted")
attr(x, "index") <- value
return(x)
}index — one of the package’s own names, itself untypedname: index
"time<-.zooreg" <- "index<-.zooreg" <- function(x, value)
{
if(length(index(x)) != length(value))
stop("length of index vectors does not match")
if(is.unsorted(ORDER(value)))
stop("new index needs to be sorted")
## check whether new index still conforms with
## frequency, if not: drop frequency
d <- try(diff(as.numeric(value)), silent = TRUE)
ok <- if(inherits(d, "try-error") || length(d) < 1 || anyNA(d)) FALSE
else {
deltat <- min(d)
dd <- d/deltat
if(identical(all.equal(dd, round(dd)), TRUE)) {
freq <- 1/deltat
if(freq > 1 && identical(all.equal(freq, round(freq)), TRUE)) freq <- round(freq)
identical(all.equal(attr(x, "frequency") %% freq, 0), TRUE)
} else {
FALSE
}
}
if(!ok) {
attr(x, "frequency") <- NULL
class(x) <- class(x)[-which(class(x) == "zooreg")]
}
attr(x, "index") <- value
return(x)
}index — one of the package’s own names, itself untypedname: index
"time<-.zoo" <- function(x, value)
{
if(length(index(x)) != length(value))
stop("length of time vectors does not match")
attr(x, "index") <- value
return(x)
}index — one of the package’s own names, itself untypedname: index
start.zoo <- function(x, ...)
{
if (length(index(x)) > 0) index(x)[1]
else NULL
}index — one of the package’s own names, itself untypedname: index
end.zoo <- function(x, ...)
{
lx <- length(index(x))
if (lx > 0) index(x)[lx]
else NULL
}UseMethod — a name the prelude does not declarename: UseMethod
index2char <- function(x, ...) UseMethod("index2char")| parameter | change | call | returned |
|---|---|---|---|
| x | kind:list | index2char.default("x" = list(), "fuzz_dot1" = NULL) | (CHR & ~vec1)<> with { } |
| x | kind:list | index2char.default("x" = list()) | (CHR & ~vec1)<> with { } |
| x | kind:sym | index2char.default("x" = as.name("x"), "fuzz_dot1" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p })) | "x"<> with { } |
| x | kind:sym | index2char.default(as.name("x"), "fuzz_dot1" = as.name("x"), "fuzz_dot2" = list(quote(f(x)))) | "x"<> with { } |
| x | wrap | index2char.default(list("NA"), list(), as.name("x"), "fuzz_dot1" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), "fuzz_dot2" = list()) | "NA"<> with { } |
| x | wrap | index2char.default(list(c(2147483647L, 1000000L)), complex(0)) | "c(2147483647, 1000000)"<> with { } |
index2char.default <- function(x, ...) as.character(x)| call | verdict | error |
|---|---|---|
| index2char.POSIXt(NA, NULL, "fuzz_dot1" = Inf) | error_type | base::prettyNum: invalid 'trim' argument |
index2char.POSIXt <- function(x, ...) format(x, ...)| call | predicted | returned |
|---|---|---|
| index2char.numeric("x" = c(TRUE, NA), "frequency" = NULL, "fuzz_dot1" = NULL, "fuzz_dot2" = NULL) | empty | (CHR & ~vec1)<> with { } |
| index2char.numeric("x" = c(NaN, -2147483647, -1, 0, 1), "fuzz_dot1" = as.name("x"), "fuzz_dot2" = quote(f(x))) | empty | (CHR & ~vec1)<> with { } |
| index2char.numeric(c(42L, NA_integer_, -1L, 2L, 1000000L), NULL, "fuzz_dot1" = list(quote(f(x)))) | empty | (CHR & ~vec1)<> with { } |
| parameter | change | call | returned |
|---|---|---|---|
| frequency | kind:dbl | index2char.numeric(c(42L, NA_integer_, -1L, 2L, 1000000L), 1.5, "fuzz_dot1" = list(quote(f(x)))) | (CHR & ~vec1)<> with { } |
| frequency | wrap | index2char.numeric("x" = new.env(), "frequency" = list(NULL), "fuzz_dot1" = NULL) | (CHR & ~vec1)<> with { } |
index2char.numeric <- function(x, frequency = NULL, digits = getOption("digits") - 3, ...)
{
freq <- frequency
if(is.null(freq)) return(as.character(round(x, digits = digits)))
if(length(x) < 1) return(character(0))
d <- diff(x)
if(freq > 1 && identical(all.equal(freq, round(freq)), TRUE)) freq <- round(freq)
if(identical(all.equal(freq*d, round(freq*d)), TRUE)) {
if(freq == 1) return(as.character(round(x)))
else return(paste(floor(x), "(", round((x - floor(x)) * freq) + 1, ")", sep = ""))
} else
return(as.character(round(x, digits = digits)))
}| call | verdict | error |
|---|---|---|
| yearmon(raw(0)) | error_type | base::*: non-numeric argument to binary operator |
| yearmon(as.raw(c(0, 0))) | error_type | base::*: non-numeric argument to binary operator |
yearmon <- function(x) structure(floor(12*x + .0001)/12, class = "yearmon")UseMethod — a name the prelude does not declarename: UseMethod
as.yearmon <- function(x, ...) UseMethod("as.yearmon")as.yearmon — one of the package’s own names, itself untypedname: as.yearmon
as.yearmon.default <- function(x, ...) as.yearmon(as.numeric(x))| call | verdict | error |
|---|---|---|
| as.yearmon.numeric("x" = as.raw(c(255))) | error_type | base::*: non-numeric argument to binary operator |
| as.yearmon.numeric(raw(0), "fuzz_dot1" = as.name("x"), "fuzz_dot2" = new.env()) | error_type | base::*: non-numeric argument to binary operator |
as.yearmon.numeric <- function(x, ...) yearmon(x)| parameter | change | call | returned |
|---|---|---|---|
| x | wrap | as.yearmon.integer(list(FALSE)) | 0.<yearmon> with { } |
| x | wrap | as.yearmon.integer("x" = list(logical(0)), "fuzz_dot1" = NULL) | (DBL1 \ ^DBL1)<yearmon> with { } |
| x | wrap | as.yearmon.integer("x" = list(NA_character_)) | (DBL1 \ ^DBL1)<yearmon> with { } |
as.yearmon.integer <- function(x, ...) structure(as.numeric(x), class = "yearmon")| parameter | change | call | returned |
|---|---|---|---|
| frac | retype:int>chr | as.yearmon.yearqtr("x" = NA_character_, "frac" = "") | (DBL1 \ ^DBL1)<yearmon> with { } |
| x | wrap | as.yearmon.yearqtr("x" = list("x y")) | (DBL1 \ ^DBL1)<yearmon> with { } |
| x | wrap | as.yearmon.yearqtr("x" = list(integer(0))) | (DBL1 \ ^DBL1)<yearmon> with { } |
as.yearmon.yearqtr <- function(x, frac = 0, ...) {
if (frac == 0) yearmon(as.numeric(x)) else
as.yearmon(as.Date(x, frac = frac), ...)
}as.POSIXlt — a name the prelude does not declarename: as.POSIXlt
as.yearmon.dates <-
as.yearmon.Date <-
as.yearmon.POSIXt <- function(x, ...) as.yearmon(with(as.POSIXlt(x, tz="GMT"), 1900 + year + mon/12))as.Date — one of the package’s own names, itself untypedname: as.Date
as.yearmon.mondate <-
as.yearmon.timeDate <-
as.yearmon.jul <- function(x, ...) as.yearmon(as.Date(x, ...))as.yearmon — one of the package’s own names, itself untypedname: as.yearmon
as.yearmon.factor <- function(x, ...) as.yearmon(as.character(x), ...)na.omit — a name the prelude does not declarename: na.omit
as.yearmon.character <- function(x, format = "", ...) {
non.na <- x[!is.na(x)]
if (length(non.na) == 0L)
return(structure(rep(NA_real_, length(x)), class = "yearmon"))
if (format == "") {
nch <- nchar(gsub("[^-]", "", x))
nch[is.na(x)] <- NA
nch <- na.omit(nch)
if (length(table(nch)) != 1)
stop("yearmon variable can only have one format")
format <- if (all(nch == 0)) "%B %Y"
else if (all(nch == 1)) "%Y-%m" else "%Y-%m-%d"
}
has.short.keys <- rep(regexpr("%[mbByY%]", format) > 0, length(x))
has.no.others <- regexpr("%", gsub("%[mbByY%]", "", format)) < 0
z <- ifelse(has.short.keys & has.no.others,
as.Date( paste("01", x, sep = "-"), paste("%d", format, sep = "-"), ... ),
as.Date(x, format, ...))
as.yearmon(as.Date(z, origin = "1970-01-01"))
}as.Date — one of the package’s own names, itself untypedname: as.Date
as.yearmon.ti <- function(x, ...) as.yearmon(as.Date(x), ...)as.Date — one of the package’s own names, itself untypedname: as.Date
as.Date.yearmon <- function(x, frac = 0, ...) {
x <- unclass(x)
if(all(is.na(x))) return(as.Date(x))
year <- floor(x + .001)
ix <- !is.na(year)
month <- floor(12 * (x - year) + 1 + .5 + .001)
dd.start <- as.Date(rep(NA, length(year)))
dd.start[ix] <- as.Date(paste(year[ix], month[ix], 1, sep = "-"))
dd.end <- dd.start + 32 - as.numeric(format(dd.start + 32, "%d"))
as.Date((1-frac) * as.numeric(dd.start) + frac * as.numeric(dd.end), origin = "1970-01-01")
}as.Date — one of the package’s own names, itself untypedname: as.Date
as.POSIXct.yearmon <- function(x, tz = "", ...) as.POSIXct(as.Date(x), tz = tz, ...)as.Date — one of the package’s own names, itself untypedname: as.Date
as.POSIXlt.yearmon <- function(x, tz = "", ...) as.POSIXlt(as.Date(x), tz = tz, ...)(((x: <@"[", ...>, ...: any) -> list<>) & ((x: v('I2528)<~@"[", ...>, ...: any) -> { v('I2528)<> }<>) & ((x: { 'I2527 }<~@"[", ...>, ...: any) -> { { 'I2527 }<> }<>))<>| parameter | change | call | returned |
|---|---|---|---|
| x | kind:lang | as.list.yearmon(quote(f(x)), list(), "fuzz_dot1" = new.env()) | { lang<> with { } }<> with { } |
| x | kind:lang | as.list.yearmon(quote(f(x)), local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), as.raw(c(255, 0, 255, 0, 0))) | { lang<> with { } }<> with { } |
| x | kind:lang | as.list.yearmon(quote(f(x)), c(2147483647L, 1000000L, 2L, 2L, 0L)) | { lang<> with { } }<> with { } |
| x | kind:null | as.list.yearmon(NULL, quote(f(x)), function(...) new.env()) | { }<> with { } |
as.list.yearmon <- function(x, ...) lapply(seq_along(x), function(i) x[i])((x: 'I2545<...>, ...: any) -> 'I2545<>)<>as.numeric.yearmon <- function(x, ...) unclass(x)as.Date — one of the package’s own names, itself untypedname: as.Date
format.yearmon <- function(x, format = "%b %Y", ...)
{
if (length(x) == 0) return(character(0))
xx <- format(as.Date(x), format = format, ...)
names(xx) <- names(x)
xx
}format.yearmon — one of the package’s own names, itself untypedname: format.yearmon
as.character.yearmon <- function(x, ...) format.yearmon(x, ...)substitute — a name the prelude does not declarename: substitute
as.data.frame.yearmon <- function(x, row.names = NULL, optional = FALSE, ...)
{
nrows <- length(x)
nm <- paste(deparse(substitute(x), width.cutoff = 500), collapse = " ")
if (is.null(row.names)) {
if (nrows == 0)
row.names <- character(0)
else if(length(row.names <- names(x)) == nrows && !any(duplicated(row.names))) {
}
else if(optional) row.names <- character(nrows)
else row.names <- seq_len(nrows)
}
names(x) <- NULL
value <- list(x)
if(!optional) names(value) <- nm
attr(value, "row.names") <- row.names
class(value) <- "data.frame"
value
}as.yearmon — one of the package’s own names, itself untypedname: as.yearmon
c.yearmon <- function(...)
as.yearmon(do.call("c", lapply(list(...), as.numeric)))| parameter | change | call | returned |
|---|---|---|---|
| x | wrap | cycle.yearmon("x" = list(-Inf)) | (^DBL1 \ (..))<> with { } |
| x | wrap | cycle.yearmon("x" = list(logical(0)), "fuzz_dot1" = function(...) list(new.env())) | (DBL1 \ ^DBL1)<> with { } |
cycle.yearmon <- function(x, ...) round(12 * (as.numeric(x) %% 1)) + 1((x: 'x, ...: any) -> 'x)<>| call | verdict | error |
|---|---|---|
| print.yearmon(structure(-1L, "levels" = c(NA_character_, "", "NA", "é", ""), class = "factor"), local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), "fuzz_dot1" = as.name("x")) | error_type | base::as.character.factor: malformed factor |
| print.yearmon(function(...) new.env(), NULL, NULL) | error_type | base::print.default: invalid 'quote' argument |
| print.yearmon(quote(f(x)), as.name("x"), list()) | error_type | base::print.default: invalid printing digits -2147483648 |
print.yearmon <- function(x, ...) {
if(length(x) == 0L) {
cat("yearmon of length 0\n")
} else {
print(format(x), ...)
}
invisible(x)
}as.Date — one of the package’s own names, itself untypedname: as.Date
months.yearmon <- function(x, abbreviate = FALSE) {
months(as.Date(x), abbreviate = abbreviate)
}as.Date — one of the package’s own names, itself untypedname: as.Date
quarters.yearmon <- function(x, abbreviate = FALSE) {
quarters(as.Date(x), abbreviate = abbreviate)
}oldClass — a name the prelude does not declarename: oldClass
"[.yearmon" <- function (x, ..., drop = TRUE)
{
cl <- oldClass(x)
class(x) <- NULL
val <- NextMethod("[")
class(val) <- cl
val
}oldClass — a name the prelude does not declarename: oldClass
"[[.yearmon" <- function (x, ..., drop = TRUE)
{
cl <- oldClass(x)
class(x) <- NULL
val <- NextMethod("[[")
class(val) <- cl
val
}oldClass — a name the prelude does not declarename: oldClass
"[<-.yearmon" <- function (x, ..., value)
{
cl <- oldClass(x)
value <- unclass(as.yearmon(value))
class(x) <- NULL
val <- NextMethod("[")
class(val) <- cl
val
}match — a name the prelude does not declarename: match
MATCH.yearmon <- function(x, table, nomatch = NA, ...)
match(floor(12*as.numeric(x) + .001), floor(12*as.numeric(table) + .001), nomatch = nomatch, ...)as.yearmon — one of the package’s own names, itself untypedname: as.yearmon
Ops.yearmon <- function(e1, e2) {
e1 <- as.numeric(as.yearmon(e1))
e2 <- as.numeric(as.yearmon(e2))
rval <- NextMethod(.Generic)
if(is.numeric(rval)) rval <- yearmon(rval)
return(rval)
}nargs — a name the prelude does not declarename: nargs
"-.yearmon" <- function (e1, e2)
{
if (!inherits(e1, "yearmon"))
stop("Can only subtract from yearmon objects")
if (nargs() == 1)
return(- as.numeric(e1))
if (inherits(e2, "yearmon"))
return(as.numeric(e1) - as.numeric(e2))
if (!is.null(attr(e2, "class")))
stop("can only subtract yearmon objects and numbers from yearmon objects")
yearmon(unclass(e1) - e2)
}| parameter | change | call | returned |
|---|---|---|---|
| x | drop | is.numeric.yearmon() | ff<> with { } |
is.numeric.yearmon <- function(x) FALSEas.yearmon — one of the package’s own names, itself untypedname: as.yearmon
axis.yearmon <- function (side, x, at, format, labels = TRUE, ..., N1 = 25, N2 = 2) {
# If years in range > N1 then only years shown.
# If years in range > N2 then month ticks are not labelled.
mat <- missing(at) || is.null(at)
if (!mat) # at not missing
x <- as.yearmon(at)
else x <- as.yearmon(x)
range <- par("usr")[if (side%%2)
1:2
else 3:4]
# range[1] <- ceiling(range[1])
# range[2] <- floor(range[2])
d <- range[2] - range[1]
z <- c(range, x[is.finite(x)])
class(z) <- "yearmon"
if (d > N1) { # axis has years only
z <- structure(pretty(z), class = "yearmon")
} else if (d > N2) { # axis has all years and unlabelled months
z <- seq(min(x), max(x), 1/12)
# z <- seq(floor(min(x)), ceiling(max(x)))
} else { # years and months
z <- seq(min(x), max(x), 1/12)
}
if (!mat)
z <- x[is.finite(x)]
z <- z[z >= range[1] & z <= range[2]]
z <- sort(unique(z))
class(z) <- "yearmon"
if (identical(labels, TRUE)) {
if (missing(format)) format <- c("%Y", "%b")
if (length(format) == 1) format <- c(format, "")
labels <- if (d <= N2) format.yearmon(z, format = format[2])
else rep(NA, length(z))
idx <- format.yearmon(z, format = "%m") == "01"
labels[idx] <- format.yearmon(z[idx], format = format[1])
} else if (identical(labels, FALSE))
labels <- rep("", length(z))
axis(side, at = z, labels = labels, ...)
}Failure("Unsupported argument after an ellipsis.")Axis.yearmon <- function(x = NULL, at = NULL, ..., side, labels = NULL)
axis.yearmon(x = x, at = at, ..., side = side, labels = TRUE)summary — a name the prelude does not declarename: summary
summary.yearmon <- function(object, ...)
summary(as.numeric(object), ...)as.Date — one of the package’s own names, itself untypedname: as.Date
as.yearmon.date <- function(x, ...) {
as.yearmon(as.Date(x, ...))
}mean — a name the prelude does not declarename: mean
mean.yearmon <- function (x, ...) as.yearmon(mean(unclass(x), ...))Failure("Unsupported positional argument after a named one.")Summary.yearmon <- function (..., na.rm)
{
ok <- switch(.Generic, max = , min = , range = TRUE, FALSE)
if (!ok) stop(.Generic, " not defined for yearmon objects")
val <- NextMethod(.Generic)
class(val) <- oldClass(list(...)[[1]])
val
}as.yearmon — one of the package’s own names, itself untypedname: as.yearmon
Sys.yearmon <- function() as.yearmon(Sys.Date())Failure("Unsupported argument after an ellipsis.")range.yearmon <- function(..., na.rm = FALSE) {
as.yearmon(range.default(..., na.rm = na.rm))
}unique.default — a name the prelude does not declarename: unique.default
unique.yearmon <- function(x, incomparables = FALSE, ...) {
as.yearmon(unique.default(x, incomparables = incomparables, ...))
}| parameter | change | call | returned |
|---|---|---|---|
| x | wrap | xtfrm.yearmon("x" = list(2L)) | 2.<> with { } |
| x | wrap | xtfrm.yearmon("x" = list(0.5)) | (^DBL1 \ (..))<> with { } |
xtfrm.yearmon <- function(x) as.numeric(x)NextMethod — a name the prelude does not declarename: NextMethod
diff.yearmon <- function(x, ...) as.numeric(NextMethod())| parameter | change | call | returned |
|---|---|---|---|
| x | kind:null | yearqtr(NULL) | (DBL & ~vec1)<yearqtr> with { } |
| x | kind:null | yearqtr("x" = NULL) | (DBL & ~vec1)<yearqtr> with { } |
| call | verdict | error |
|---|---|---|
| yearqtr(as.raw(c(255, 255, 0, 0, 0))) | error_type | base::*: non-numeric argument to binary operator |
| yearqtr(as.raw(c(0))) | error_type | base::*: non-numeric argument to binary operator |
| yearqtr("x" = as.raw(c(255))) | error_type | base::*: non-numeric argument to binary operator |
yearqtr <- function(x) structure(floor(4*x + .001)/4, class = "yearqtr")UseMethod — a name the prelude does not declarename: UseMethod
as.yearqtr <- function(x, ...) UseMethod("as.yearqtr")as.yearqtr — one of the package’s own names, itself untypedname: as.yearqtr
as.yearqtr.default <- function(x, ...) as.yearqtr(as.numeric(x))| parameter | change | call | returned |
|---|---|---|---|
| x | kind:null | as.yearqtr.numeric("x" = NULL, "fuzz_dot1" = as.name("x")) | (DBL & ~vec1)<yearqtr> with { } |
| call | verdict | error |
|---|---|---|
| as.yearqtr.numeric(as.raw(c(0)), "fuzz_dot1" = new.env(), "fuzz_dot2" = function(...) as.name("x")) | error_type | base::*: non-numeric argument to binary operator |
| as.yearqtr.numeric("x" = as.raw(c(0)), "fuzz_dot1" = new.env(), "fuzz_dot2" = list()) | error_type | base::*: non-numeric argument to binary operator |
as.yearqtr.numeric <- function(x, ...) yearqtr(x)| parameter | change | call | returned |
|---|---|---|---|
| x | wrap | as.yearqtr.integer("x" = list(logical(0)), "fuzz_dot1" = NULL, "fuzz_dot2" = new.env()) | (DBL1 \ ^DBL1)<yearqtr> with { } |
as.yearqtr.integer <- function(x, ...) structure(as.numeric(x), class = "yearqtr")as.yearmon — one of the package’s own names, itself untypedname: as.yearmon
as.yearqtr.mondate <-
as.yearqtr.jul <- # jul is in tis package
as.yearqtr.timeDate <-
as.yearqtr.dates <-
as.yearqtr.Date <-
as.yearqtr.POSIXt <- function(x, ...) as.yearqtr(as.yearmon(x))((x: 'x, ...: any) -> 'x)<>as.yearqtr.yearqtr <- function(x, ...) xas.yearqtr — one of the package’s own names, itself untypedname: as.yearqtr
as.yearqtr.factor <- function(x, ...) as.yearqtr(as.character(x), ...)as.yearmon — one of the package’s own names, itself untypedname: as.yearmon
as.yearqtr.character <- function(x, format, ...) {
non.na <- x[!is.na(x)]
if (length(non.na) == 0L)
return(structure(rep(NA_real_, length(x)), class = "yearqtr"))
if (missing(format) || format == "") {
format <- if (all(regexpr("q", non.na) > 0)) { "%Y q%q"
} else if (all(regexpr("Q", non.na) > 0)) { "%Y Q%q"
} else "%Y-%q"
}
y <- if (regexpr("%[qQ]", format) > 0) {
format <- sub("%q", "%m", format)
y <- as.numeric(as.yearmon(x, format))
m0 <- round(12 * (y %% 1))
floor(y) + ifelse(m0 > 3, NA, m0/4)
} else as.yearmon(x, format)
as.yearqtr(y)
}as.Date — one of the package’s own names, itself untypedname: as.Date
as.yearqtr.ti <- function(x, ...) as.yearqtr(as.Date(x), ...)as.Date — one of the package’s own names, itself untypedname: as.Date
as.Date.yearqtr <- function(x, frac = 0, ...) {
x <- unclass(x)
if(all(is.na(x))) return(as.Date(x))
year <- floor(x + .001)
ix <- !is.na(year)
month <- floor(12 * (x - year) + 1 + .5 + .001)
dd.start <- as.Date(rep(NA, length(year)))
dd.start[ix] <- as.Date(paste(year[ix], month[ix], 1, sep = "-"))
dd.end <- dd.start + 100 - as.numeric(format(dd.start + 100, "%d"))
as.Date((1-frac) * as.numeric(dd.start) + frac * as.numeric(dd.end), origin = "1970-01-01")
}as.Date — one of the package’s own names, itself untypedname: as.Date
as.POSIXct.yearqtr <- function(x, tz = "", ...) as.POSIXct(as.Date(x), tz = tz, ...)as.Date — one of the package’s own names, itself untypedname: as.Date
as.POSIXlt.yearqtr <- function(x, tz = "", ...) as.POSIXlt(as.Date(x), tz = tz, ...)(((x: <@"[", ...>, ...: any) -> list<>) & ((x: v('I3388)<~@"[", ...>, ...: any) -> { v('I3388)<> }<>) & ((x: { 'I3387 }<~@"[", ...>, ...: any) -> { { 'I3387 }<> }<>))<>| parameter | change | call | returned |
|---|---|---|---|
| x | kind:env | as.list.yearqtr(new.env(), list(), "fuzz_dot1" = as.name("x"), "fuzz_dot2" = FALSE) | { }<> with { } |
| x | kind:null | as.list.yearqtr("x" = NULL) | { }<> with { } |
| x | kind:null | as.list.yearqtr("x" = NULL, "fuzz_dot1" = new.env(), "fuzz_dot2" = list(local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), as.name("x"))) | { }<> with { } |
as.list.yearqtr <- function(x, ...) lapply(seq_along(x), function(i) x[i])((x: 'I3405<...>, ...: any) -> 'I3405<>)<>as.numeric.yearqtr <- function(x, ...) unclass(x)Invalid_argument("Variable ..._5 is already bound.")format.yearqtr <- function(x, format = "%Y Q%q", ...)
{
if (length(x) == 0) return(character(0))
# like gsub but replacement and x may be vectors the same length
gsub.vec <- function(pattern, replacement, x, ...) {
y <- x
for(i in seq_along(x)) {
y[i] <- gsub(pattern, replacement[i], x[i], ...)
}
y
}
x <- as.yearqtr(x)
x <- unclass(x)
year <- floor(x + .001)
qtr <- floor(4*(x - year) + 1 + .5 + .001)
xx <- if (format == "%Y Q%q") {
paste(year, " Q", qtr, sep = "")
} else {
# TODO: speed up the following
xx <- gsub.vec("%q", qtr, rep.int(format, length(qtr)))
xx <- gsub.vec("%Y", year, xx)
xx <- gsub.vec("%y", sprintf("%02d", as.integer(year %% 100)), xx)
xx <- gsub.vec("%C", year %/% 100, xx)
xx
}
names(xx) <- names(x)
xx[is.na(x)] <- NA_character_
return(xx)
}format.yearqtr — one of the package’s own names, itself untypedname: format.yearqtr
as.character.yearqtr <- function(x, ...) format.yearqtr(x, ...)substitute — a name the prelude does not declarename: substitute
as.data.frame.yearqtr <- function(x, row.names = NULL, optional = FALSE, ...)
{
nrows <- length(x)
nm <- paste(deparse(substitute(x), width.cutoff = 500), collapse = " ")
if (is.null(row.names)) {
if (nrows == 0)
row.names <- character(0)
else if(length(row.names <- names(x)) == nrows && !any(duplicated(row.names))) {
}
else if(optional) row.names <- character(nrows)
else row.names <- seq_len(nrows)
}
names(x) <- NULL
value <- list(x)
if(!optional) names(value) <- nm
attr(value, "row.names") <- row.names
class(value) <- "data.frame"
value
}as.yearqtr — one of the package’s own names, itself untypedname: as.yearqtr
c.yearqtr <- function(...) {
as.yearqtr(do.call("c", lapply(list(...), as.numeric)))
}| parameter | change | call | returned |
|---|---|---|---|
| x | wrap | cycle.yearqtr("x" = list(-1), "fuzz_dot1" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), "fuzz_dot2" = NULL) | 1.<> with { } |
| x | wrap | cycle.yearqtr(list(1000000L), NULL, quote(f(x)), "fuzz_dot1" = new.env(), "fuzz_dot2" = as.name("x")) | 1.<> with { } |
cycle.yearqtr <- function(x, ...) round(4 * (as.numeric(x) %% 1)) + 1as.Date — one of the package’s own names, itself untypedname: as.Date
months.yearqtr <- function(x, abbreviate = FALSE) {
months(as.Date(x), abbreviate = abbreviate)
}as.Date — one of the package’s own names, itself untypedname: as.Date
quarters.yearqtr <- function(x, abbreviate = FALSE) {
quarters(as.Date(x), abbreviate = abbreviate)
}((x: 'x, ...: any) -> 'x)<>| call | verdict | error |
|---|---|---|
| print.yearqtr(NA_complex_, as.name("x"), "fuzz_dot1" = quote(f(x)), "fuzz_dot2" = NULL) | error_type | base::print.default: invalid printing digits -2147483648 |
| print.yearqtr(as.raw(c(255)), complex(0), function(...) quote(f(x)), "fuzz_dot1" = as.name("x")) | error_type | base::print.default: invalid printing digits -2147483648 |
| print.yearqtr("", list(), as.raw(c(0))) | error_type | base::print.default: invalid printing digits -2147483648 |
| print.yearqtr(list("a" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p })), local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), "fuzz_dot1" = new.env()) | error_type | base::print.default: invalid printing digits -2147483648 |
print.yearqtr <- function(x, ...) {
if(length(x) == 0L) {
cat("yearqtr of length 0\n")
} else {
print(format(x), ...)
}
invisible(x)
}oldClass — a name the prelude does not declarename: oldClass
"[.yearqtr" <- function (x, ..., drop = TRUE)
{
cl <- oldClass(x)
class(x) <- NULL
val <- NextMethod("[")
class(val) <- cl
val
}oldClass — a name the prelude does not declarename: oldClass
"[[.yearqtr" <- function (x, ..., drop = TRUE)
{
cl <- oldClass(x)
class(x) <- NULL
val <- NextMethod("[[")
class(val) <- cl
val
}oldClass — a name the prelude does not declarename: oldClass
"[<-.yearqtr" <- function (x, ..., value)
{
cl <- oldClass(x)
value <- unclass(as.yearqtr(value))
class(x) <- NULL
val <- NextMethod("[")
class(val) <- cl
val
}match — a name the prelude does not declarename: match
MATCH.yearqtr <- function(x, table, nomatch = NA, ...)
match(floor(4*as.numeric(x) + .001), floor(4*as.numeric(table) + .001), nomatch = nomatch, ...)as.yearqtr — one of the package’s own names, itself untypedname: as.yearqtr
Ops.yearqtr <- function(e1, e2) {
e1 <- as.numeric(as.yearqtr(e1))
e2 <- as.numeric(as.yearqtr(e2))
rval <- NextMethod(.Generic)
if(is.numeric(rval)) rval <- yearqtr(rval)
return(rval)
}nargs — a name the prelude does not declarename: nargs
"-.yearqtr" <- function (e1, e2)
{
if (!inherits(e1, "yearqtr"))
stop("Can only subtract from yearqtr objects")
if (nargs() == 1)
return(- as.numeric(e1))
if (inherits(e2, "yearqtr"))
return(as.numeric(e1) - as.numeric(e2))
if (!is.null(attr(e2, "class")))
stop("can only subtract yearqtr objects and numbers from yearqtr objects")
yearqtr(unclass(e1) - e2)
}| parameter | change | call | returned |
|---|---|---|---|
| x | drop | is.numeric.yearqtr() | ff<> with { } |
is.numeric.yearqtr <- function(x) FALSEas.yearqtr — one of the package’s own names, itself untypedname: as.yearqtr
axis.yearqtr <- function (side, x, at, format, labels = TRUE, ..., N1 = 25, N2 = 7) {
# If years in range > N1 then only years shown.
# If years in range > N2 then quarter ticks are not labelled.
mat <- missing(at) || is.null(at)
if (!mat) # at not missing
x <- as.yearqtr(at)
else x <- as.yearqtr(x)
range <- par("usr")[if (side%%2)
1:2
else 3:4]
# range[1] <- ceiling(range[1])
# range[2] <- floor(range[2])
d <- range[2] - range[1]
z <- c(range, x[is.finite(x)])
class(z) <- "yearqtr"
if (d > N1) { # axis has years only
z <- structure(pretty(z), class = "yearqtr")
} else if (d > N2) { # axis has all years and unlabelled quarters
z <- seq(min(x), max(x), 0.25)
# z <- seq(floor(min(x)), ceiling(max(x)))
} else { # years and quarters
z <- seq(min(x), max(x), 0.25)
}
if (!mat)
z <- x[is.finite(x)]
z <- z[z >= range[1] & z <= range[2]]
z <- sort(unique(z))
class(z) <- "yearqtr"
if (identical(labels, TRUE)) {
if (missing(format)) format <- c("%Y", "Q%q")
if (length(format) == 1) format <- c(format, "")
if (d <= N2) labels <- format.yearqtr(z, format = format[2])
idx <- format.yearqtr(z, format = "%q") == "1"
labels <- rep(NA, length(z))
labels[idx] <- format.yearqtr(z[idx], format = format[1])
} else if (identical(labels, FALSE))
labels <- rep("", length(z))
axis(side, at = z, labels = labels, ...)
}Failure("Unsupported argument after an ellipsis.")Axis.yearqtr <- function(x = NULL, at = NULL, ..., side, labels = NULL)
axis.yearqtr(x = x, at = at, ..., side = side, labels = TRUE)summary — a name the prelude does not declarename: summary
summary.yearqtr <- function(object, ...)
summary(as.numeric(object), ...)as.Date — one of the package’s own names, itself untypedname: as.Date
as.yearqtr.date <- function(x, ...) {
as.yearqtr(as.Date(x, ...))
}mean — a name the prelude does not declarename: mean
mean.yearqtr <- function (x, ...) as.yearqtr(mean(unclass(x), ...))Failure("Unsupported positional argument after a named one.")Summary.yearqtr <- function (..., na.rm)
{
ok <- switch(.Generic, max = , min = , range = TRUE, FALSE)
if (!ok) stop(.Generic, " not defined for yearqtr objects")
val <- NextMethod(.Generic)
class(val) <- oldClass(list(...)[[1]])
val
}as.yearqtr — one of the package’s own names, itself untypedname: as.yearqtr
Sys.yearqtr <- function() as.yearqtr(Sys.Date())Failure("Unsupported argument after an ellipsis.")range.yearqtr <- function(..., na.rm = FALSE) {
as.yearqtr(range.default(..., na.rm = na.rm))
}unique.default — a name the prelude does not declarename: unique.default
unique.yearqtr <- function(x, incomparables = FALSE, ...) {
as.yearqtr(unique.default(x, incomparables = incomparables, ...))
}| parameter | change | call | returned |
|---|---|---|---|
| x | wrap | xtfrm.yearqtr(list(2147483647L)) | 2147483647.<> with { } |
| x | wrap | xtfrm.yearqtr("x" = list(TRUE)) | 1.<> with { } |
xtfrm.yearqtr <- function(x) as.numeric(x)NextMethod — a name the prelude does not declarename: NextMethod
diff.yearqtr <- function(x, ...) as.numeric(NextMethod())index — one of the package’s own names, itself untypedname: index
zoo <- function (x = NULL, order.by = index(x), frequency = NULL,
calendar = getOption("zoo.calendar", TRUE))
{
## process index "order.by"
if(length(unique(MATCH(order.by, order.by))) < length(order.by))
warning(paste("some methods for", dQuote("zoo"),
"objects do not work if the index entries in", sQuote("order.by"), "are not unique"))
index <- ORDER(order.by)
order.by <- order.by[index]
if(is.matrix(x) || is.data.frame(x)) x <- as.matrix(x)
if(is.matrix(x) && sum(dim(x)) < 1L) x <- NULL
if(missing(x) || is.null(x))
x <- numeric()
else if(is.factor(x))
x <- factor(rep(as.character(x), length.out = length(index))[index],
levels = levels(x), ordered = is.ordered(x))
else if(is.matrix(x) || is.data.frame(x))
x <- (x[rep(1:NROW(x), length.out = length(index)), ,
drop = FALSE])[index, , drop = FALSE]
else if(is.atomic(x))
x <- rep(x, length.out = length(index))[index]
else stop(paste(dQuote("x"), ": attempt to define invalid zoo object"))
if(!is.null(frequency)) {
delta <- suppressWarnings(try(diff(as.numeric(order.by)), silent = TRUE))
freqOK <- if(inherits(delta, "try-error") || anyNA(delta)) FALSE
else if(length(delta) < 1) TRUE
else identical(all.equal(delta*frequency, round(delta*frequency)), TRUE)
if(!freqOK) {
warning(paste(dQuote("order.by"), "and", dQuote("frequency"),
"do not match:", dQuote("frequency"), "ignored"))
frequency <- NULL
} else {
if(frequency > 1 && identical(all.equal(frequency, round(frequency)), TRUE))
frequency <- round(frequency)
}
if(!is.null(frequency) && identical(class(order.by), "numeric") | identical(class(order.by), "integer")) {
orig.order.by <- order.by
order.by <- floor(frequency * order.by + .0001)/frequency
if(!isTRUE(all.equal(order.by, orig.order.by))) order.by <- orig.order.by
if(calendar && frequency %in% c(4, 12)) {
order.by <- if(frequency == 4) as.yearqtr(order.by) else as.yearmon(order.by)
}
}
}
attr(x, "oclass") <- attr(x, "class")
attr(x, "index") <- order.by
attr(x, "frequency") <- frequency
class(x) <- if(is.null(frequency)) "zoo" else c("zooreg", "zoo")
return(x)
}ifelse — a name the prelude does not declarename: ifelse
print.zoo <- function (x, style = ifelse(length(dim(x)) == 0,
"horizontal", "vertical"), quote = FALSE, ...)
{
style <- match.arg(style, c("horizontal", "vertical", "plain"))
if (is.null(dim(x)) && length(x) == 0) style <- "plain"
if (length(dim(x)) > 0 && style == "horizontal") style <- "plain"
if (style == "vertical") {
y <- as.matrix(coredata(x))
if (length(colnames(x)) < 1) {
colnames(y) <- rep("", NCOL(x))
}
if (NROW(y) > 0) {
rownames(y) <- index2char(index(x), frequency = attr(x, "frequency"))
}
print(y, quote = quote, ...)
}
else if (style == "horizontal") {
y <- as.vector(x)
names(y) <- index2char(index(x), frequency = attr(x, "frequency"))
print(y, quote = quote, ...)
}
else {
cat("Data:\n")
print(coredata(x))
cat("\nIndex:\n")
print(index(x))
}
invisible(x)
}as.data.frame — a name the prelude does not declarename: as.data.frame
summary.zoo <- function(object, ...)
{
y <- as.data.frame(object, row.names = NULL)
if (length(colnames(object)) < 1) {
lab <- deparse(substitute(object))
colnames(y) <- if (NCOL(object) == 1) lab
else paste(lab, 1:NCOL(object), sep=".")
}
if (NROW(y) > 0) {
summary(cbind(data.frame(Index = index(object)), y), ...)
} else summary(data.frame(Index = index(object)), ...)
}is.zoo <- function(object)
inherits(object, "zoo")NROW — a name the prelude does not declarename: NROW
str.zoo <- function(object, ...)
{
cls <- if(inherits(object, "zooreg")) "zooreg" else "zoo"
if(NROW(object) < 1) cat(paste(sQuote(cls), "series (without observations)\n")) else {
cat(paste(sQuote(cls), " series from ", start(object), " to ", end(object), "\n", sep = ""))
cat(" Data:")
str(coredata(object), ...)
cat(" Index: ")
str(index(object), ...)
if(cls == "zooreg") cat(paste(" Frequency:", attr(object, "frequency"), "\n"))
}
}coredata — one of the package’s own names, itself untypedname: coredata
"[.zoo" <- function(x, i, j, drop = TRUE, ...)
{
if(!is.zoo(x)) stop("method is only for zoo objects")
rval <- coredata(x)
n <- NROW(rval)
n2 <- if(nargs() == 1) length(as.vector(rval)) else n
if(missing(i)) i <- 1:n
if (inherits(i, "matrix")) i <- as.vector(i)
## also support that i can be index:
## if i is not numeric/integer/logical, it is interpreted to be the index
if (inherits(i, "logical"))
i <- which(rep(i, length.out = n2))
else if (inherits(i, "zoo") && inherits(coredata(i), "logical")) {
i <- which(coredata(merge(zoo(,time(x)), i)))
} else if(!((inherits(i, "numeric") || inherits(i, "integer"))))
i <- which(MATCH(index(x), i, nomatch = 0L) > 0L)
if(length(dim(rval)) == 2) {
drop. <- if (length(i) == 1) FALSE else drop
rval <- if (missing(j)) rval[i, , drop = drop., ...]
else rval[i, j, drop = drop., ...]
if (drop && length(rval) == 1) rval <- c(rval)
rval <- zoo(rval, index(x)[i])
} else
rval <- zoo(rval[i], index(x)[i])
attr(rval, "oclass") <- attr(x, "oclass")
attr(rval, "levels") <- attr(x, "levels")
attr(rval, "frequency") <- attr(x, "frequency")
if(!is.null(attr(rval, "frequency"))) class(rval) <- c("zooreg", class(rval))
return(rval)
}NextMethod — a name the prelude does not declarename: NextMethod
"[<-.zoo" <- function (x, i, j, value)
{
## x[,j] <- value and x[] <- value can be handled by default method
if(missing(i)) return(NextMethod("[<-"))
## otherwise do the necessary processing on i
n <- NROW(coredata(x))
n2 <- if(nargs() == 1) length(as.vector(coredata(x))) else n
n.ok <- TRUE
value2 <- NULL
if (inherits(i, "matrix")) i <- as.vector(i)
if (inherits(i, "logical")) {
if (length(i) == n) {
i <- which(i)
n.ok <- TRUE
} else {
i <- which(rep(i, length.out = n))
n.ok <- all(i <= n2)
}
} else if (inherits(i, "zoo") && inherits(coredata(i), "logical")) {
i <- which(coredata(merge(zoo(,time(x)), i)))
n.ok <- all(i <= n2)
} else if(!((inherits(i, "numeric") || inherits(i, "integer")))) {
## all time indexes in index(x)?
i.ok <- MATCH(i, index(x), nomatch = 0L) > 0L
if(any(!i.ok)) {
if(is.null(dim(value))) {
value2 <- value[!i.ok]
value <- value[i.ok]
} else {
value2 <- value[!i.ok,, drop = FALSE]
value <- value[i.ok,, drop = FALSE]
}
i2 <- i[!i.ok]
i <- i[i.ok]
}
i <- which(MATCH(index(x), i, nomatch = 0L) > 0L)
n.ok <- all(i <= n2)
}
if(!n.ok | any(i < 1)) stop("Out-of-range assignment not possible.")
rval <- NextMethod("[<-")
if(!is.null(value2)) {
rval2 <- if(missing(j)) zoo(value2, i2) else {
value2a <- matrix(NA, nrow = length(i2), ncol = NCOL(rval))
colnames(value2a) <- colnames(rval)
value2a[, j] <- value2
zoo(value2a, i2)
}
rval <- c(rval, rval2)
}
return(rval)
}dimnames — a name the prelude does not declarename: dimnames
.DollarNames.zoo <- function(x, pattern = "") {
dn <- dimnames(x)
if(is.null(dn)) {
character(0)
} else {
cn <- dn[[2]]
if(is.null(cn)) {
character(0)
} else {
grep(pattern, cn, value = TRUE)
}
}
}colnames — a name the prelude does not declarename: colnames
"$.zoo" <- function(object, x) {
if(length(dim(object)) != 2) stop("not possible for univariate zoo series")
if(is.null(colnames(object))) stop("only possible for zoo series with column names")
wi <- pmatch(x, colnames(object))
if(is.na(wi)) NULL else object[, wi]
}index — one of the package’s own names, itself untypedname: index
"$<-.zoo" <- function(object, x, value) {
if(length(object) == 0L) {
is.plain <- function(x)
all(class(x) %in% c("array", "integer", "numeric", "factor", "matrix", "logical"))
if(is.plain(value)) value <- zoo(value,
if(length(index(object))) index(object) else seq_along(value), attr(object, "frequency"))
return(setNames(merge(object, value, drop = FALSE), x))
}
if(length(dim(object)) != 2) stop("not possible for univariate zoo series")
if(NCOL(object) > 0L && is.null(cnam <- colnames(object))) stop("only possible for zoo series with column names")
wi <- match(x, cnam)
if(is.na(wi)) {
if(!is.null(value)) {
object <- cbind(object, value)
if(is.null(dim(object))) dim(object) <- c(length(object), 1)
if(!identical(colnames(object), cnam)) colnames(object)[NCOL(object)] <- x
}
} else {
if(is.null(value)) {
object <- object[, -wi, drop = FALSE]
} else {
object[, wi] <- value
}
}
object
}NROW — a name the prelude does not declarename: NROW
head.zoo <- function(x, n = 6, ...) {
stopifnot(length(n) == 1L)
xlen <- NROW(x)
n <- if (n < 0L)
max(NROW(x) + n, 0L)
else min(n, xlen)
if (length(dim(x)) == 0) x[seq_len(n)]
else x[seq_len(n),, drop = FALSE]
}NROW — a name the prelude does not declarename: NROW
tail.zoo <- function(x, n = 6, ...) {
stopifnot(length(n) == 1L)
xlen <- NROW(x)
n <- if (n < 0L)
max(xlen + n, 0L)
else min(n, xlen)
if (length(dim(x)) == 0) x[seq.int(to = xlen, length.out = n)]
else x[seq.int(to = xlen, length.out = n),, drop = FALSE]
}coredata — one of the package’s own names, itself untypedname: coredata
range.zoo <- function(..., na.rm = FALSE)
range(sapply(list(...), coredata), na.rm = na.rm)coredata — one of the package’s own names, itself untypedname: coredata
scale.zoo <- function (x, center = TRUE, scale = TRUE) {
x[] <- xs <- scale(coredata(x), center = center, scale = scale)
attributes(x) <- c(attributes(x), attributes(xs))
x
}substitute — a name the prelude does not declarename: substitute
with.zoo <- function(data, expr, ...) {
stopifnot(length(dim(data)) == 2)
eval(substitute(expr), as.list(data), enclos = parent.frame())
}coredata — one of the package’s own names, itself untypedname: coredata
xtfrm.zoo <- function(x) coredata(x)argument: @(1.<>, INT1<> | null) failing call: base:::(1, NULL)
subset.zoo <- function (x, subset, select, drop = FALSE, ...)
{
if (missing(select))
vars <- TRUE
else {
nl <- as.list(1:ncol(x))
names(nl) <- colnames(x)
vars <- eval(substitute(select), nl, parent.frame())
}
if (missing(subset)) {
subset <- rep(TRUE, NROW(x))
} else {
e <- substitute(subset)
if("time" %in% colnames(x)) {
xdf <- as.data.frame(x)
subset <- eval(e, xdf, parent.frame())
xdf$time <- time(x)
subset2 <- eval(e, xdf, parent.frame())
if(!identical(subset, subset2))
warning("'time' is a column in 'x' (not the time index)")
} else {
subset <- eval(e, cbind(as.data.frame(x), time = time(x)), parent.frame())
}
if (!is.logical(subset)) stop("'subset' must be logical")
}
x[subset & !is.na(subset), vars, drop = drop]
}coredata — one of the package’s own names, itself untypedname: coredata
names.zoo <- function(x) {
cx <- coredata(x)
if(is.matrix(cx)) colnames(cx) else names(cx)
}coredata — one of the package’s own names, itself untypedname: coredata
"names<-.zoo" <- function(x, value) {
if(is.matrix(coredata(x))) {
colnames(x) <- value
} else {
names(coredata(x)) <- value
}
x
}time — a name the prelude does not declarename: time
rev.zoo <- function(x) {
ix <- rev(ORDER(time(x)))
zoo(coredata(x), time(x)[ix])
}index — one of the package’s own names, itself untypedname: index
ifelse.zoo <- function(test, yes, no) {
if(!is.zoo(test)) test <- zoo(test, index(yes))
merge(test, yes, no, retclass = NULL)
ifelse(test, yes, no)
}coredata — one of the package’s own names, itself untypedname: coredata
mean.zoo <- function(x, ...) mean(coredata(x), ...)getRversion — a name the prelude does not declarename: getRversion
median.zoo <- if(getRversion() <= "3.3.3") {
function(x, na.rm = FALSE) median(coredata(x), na.rm = na.rm)
} else {
function(x, na.rm = FALSE, ...) median(coredata(x), na.rm = na.rm, ...)
}coredata — one of the package’s own names, itself untypedname: coredata
quantile.zoo <- function(x, ...) quantile(coredata(x), ...)coredata — one of the package’s own names, itself untypedname: coredata
transform.zoo <- function(`_data`, ...)
{
## turn zoo matrix into a list of zoo series
if (is.null(dim(coredata(`_data`)))) warning("transform() is only useful for matrix-based zoo series")
`_data` <- as.list(`_data`)
## evaluate transformations
e <- eval(substitute(list(...)), `_data`, parent.frame())
## zoo series that are replaced
inx <- match(names(e), names(`_data`))
matched <- !is.na(inx)
if (any(matched)) `_data`[inx[matched]] <- e[matched]
## merge zoo series (including those that are added)
z <- do.call("merge", c(`_data`, e[!matched]))
## always return a zoo matrix (even if just one column)
if(is.null(dim(coredata(z)))) {
dim(z) <- c(length(z), 1L)
names(z) <- names(e)
}
return(z)
}all.equal — a name the prelude does not declarename: all.equal
`dim<-.zoo` <- function(x, value) {
d <- dim(x)
l <- length(x)
ok <- isTRUE(all.equal(d, value)) || ## no change
(is.null(d) && l == 0L && all(value == c(length(index(x)), 0L))) || ## zero-length vector -> 0-column matrix
(is.null(d) && l > 0L && all(value == c(l, 1L))) || ## positive-length vector -> 1-column matrix
(!is.null(d) && d[2L] <= 1L && is.null(value)) ## 0- or 1-column matrix -> vector
if(!ok) warning("setting this dimension may lead to an invalid zoo object")
NextMethod()
}UseMethod — a name the prelude does not declarename: UseMethod
is.regular <- function(x, strict = FALSE) {
UseMethod("is.regular")
}index — one of the package’s own names, itself untypedname: index
is.regular.zoo <- function(x, strict = FALSE)
{
delta <- suppressWarnings(try(diff(as.numeric(index(x))), silent = TRUE))
if(inherits(delta, "try-error") || anyNA(delta)) FALSE
else if(length(delta) < 1) FALSE
else if(strict) identical(all.equal(delta, rep.int(delta[1], length(delta))), TRUE)
else {
delta <- unique(delta)
rval <- identical(all.equal(delta/min(delta), round(delta/min(delta))), TRUE)
if(!rval && identical(all.equal(delta, round(delta)), TRUE)) rval <- TRUE
rval
}
}| parameter | change | call | returned |
|---|---|---|---|
| x | drop | is.regular.ts("strict" = as.name("x")) | tt<> with { } |
| x | drop | is.regular.ts() | tt<> with { } |
is.regular.ts <- function(x, strict = FALSE) TRUE| parameter | change | call | returned |
|---|---|---|---|
| strict | retype:lgl>raw | is.regular.zooreg(quote(f(x)), as.raw(c(255))) | tt<> with { } |
| strict | retype:lgl>raw | is.regular.zooreg("x" = c(complex(real = 0, imaginary = 0), complex(real = 0, imaginary = 0)), "strict" = as.raw(c(255))) | tt<> with { } |
| x | drop | is.regular.zooreg() | tt<> with { } |
is.regular.zooreg <- function(x, strict = FALSE)
{
if(strict) is.regular.zoo(x, strict = TRUE) else TRUE
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
is.regular.default <- function(x, strict = FALSE) {
is.regular(as.zoo(x), strict = strict)
}((x: any with { frequency: 'I5108, any }, ...: any) -> 'I5108)<>| parameter | change | call | returned |
|---|---|---|---|
| x | attr:drop:frequency | frequency.zooreg("x" = quote(f(x)), "fuzz_dot1" = as.name("x"), "fuzz_dot2" = new.env()) | null |
| x | attr:drop:frequency | frequency.zooreg("x" = c(-2.5, 42, 0, Inf, Inf), "fuzz_dot1" = complex(real = 0, imaginary = 0)) | null |
| x | attr:drop:frequency | frequency.zooreg(function(...) as.name("x"), NULL) | null |
| x | attr:drop:frequency | frequency.zooreg("x" = c("NA", "x y", "x y", "", "é"), "fuzz_dot1" = NULL) | null |
| x | kind:chr | frequency.zooreg("fuzz") | null |
| x | kind:fun | frequency.zooreg(function(...) NULL, list()) | null |
frequency.zooreg <- function(x, ...)
{
attr(x, "frequency")
}((x: any with { frequency: 'I5223 \ null, any }, ...: any) -> 'I5223)<>| parameter | change | call | returned |
|---|---|---|---|
| x | attr:drop:frequency | frequency.zoo("x" = new.env()) | null |
| x | attr:drop:frequency | frequency.zoo(list(), function(...) new.env(), function(...) quote(f(x))) | null |
| x | kind:chr | frequency.zoo("x" = "fuzz", "fuzz_dot1" = list(), "fuzz_dot2" = quote(f(x))) | null |
| x | kind:fun | frequency.zoo("x" = function(...) NULL, "fuzz_dot1" = function(...) quote(f(x)), "fuzz_dot2" = function(...) as.name("x")) | null |
| x | kind:fun | frequency.zoo(function(...) NULL, NULL, "fuzz_dot1" = NULL, "fuzz_dot2" = new.env()) | null |
| x | wrap | frequency.zoo(list(structure(function(...) 0.5, "frequency" = c(NA_real_, NaN, 2147483647, 2147483647, -Inf))), new.env(), as.name("x"), "fuzz_dot1" = quote(f(x))) | null |
frequency.zoo <- function(x, ...)
{
## check whether frequency is available
freq <- attr(x, "frequency")
if(!is.null(freq) || length(index(x)) < 2) return(freq)
## check regularity
delta <- suppressWarnings(try(diff(as.numeric(index(x))), silent = TRUE))
reg <- if(inherits(delta, "try-error") || anyNA(delta)) FALSE
else {
delta <- unique(delta)
rval <- identical(all.equal(delta/min(delta), round(delta/min(delta))), TRUE)
if(rval) freq <- 1/min(delta)
else if(identical(all.equal(delta, round(delta)), TRUE)) {
## special case: integer indexes
## get frequency as greatest common divisor (of differences)
gcd <- function(x) {
gcd0 <- function(a, b) ifelse(b==0 | a==b, a, gcd0(b, a %% b))
if(length(x) < 2) x <- c(x, as.integer(0))
if(length(x) < 3) {
return(gcd0(x[1], x[2]))
} else {
x <- sapply(1:(length(x) - 1), function(i) gcd0(x[i], x[i+1]))
gcd(x)
}
}
freq <- 1/gcd(delta)
rval <- TRUE
}
rval
}
if(!reg) return(NULL)
if(freq > 1 && identical(all.equal(freq, round(freq)), TRUE)) freq <- round(freq)
return(freq)
}UseMethod — a name the prelude does not declarename: UseMethod
"frequency<-" <- function(x, value)
UseMethod("frequency<-")index — one of the package’s own names, itself untypedname: index
"frequency<-.zoo" <- function(x, value) {
delta <- suppressWarnings(try(diff(as.numeric(index(x))), silent = TRUE))
freqOK <- if(inherits(delta, "try-error") || anyNA(delta)) FALSE
else if(length(delta) < 1) TRUE
else identical(all.equal(delta*value, round(delta*value)), TRUE)
stopifnot(freqOK)
if(value > 1 && identical(all.equal(value, round(value)), TRUE)) value <- round(value)
attr(x, "frequency") <- value
class(x) <- c("zooreg", "zoo")
return(x)
}index — one of the package’s own names, itself untypedname: index
"frequency<-.zooreg" <- function(x, value) {
delta <- diff(as.numeric(index(x)))
stopifnot(identical(all.equal(delta*value, round(delta*value)), TRUE))
attr(x, "frequency") <- value
return(x)
}(((x: any with { frequency: dbl1<. | `I357>, any }, ...: any) -> DBL1<. | `I357>) & ((x: any with { frequency: dbl<. | `I357>, any }, ...: any) -> DBL<. | `I357>))<>| parameter | change | call | returned |
|---|---|---|---|
| x | attr:drop:frequency | deltat.zoo("x" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p })) | null |
| x | drop | deltat.zoo(local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), "fuzz_dot1" = NULL) | null |
| x | drop | deltat.zoo(as.name("x"), 0L, "fuzz_dot1" = function(...) NULL, "fuzz_dot2" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p })) | null |
| x | kind:dbl | deltat.zoo("x" = 1.5, "fuzz_dot1" = c(NA_character_, NA_character_, "", "x y", "NA")) | null |
| x | kind:env | deltat.zoo(new.env(), as.raw(c(0, 255, 0, 0, 255)), NULL, "fuzz_dot1" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p })) | null |
| x | kind:null | deltat.zoo(NULL, character(0), "fuzz_dot1" = new.env(), "fuzz_dot2" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p })) | null |
| call | verdict | error |
|---|---|---|
| deltat.zoo("x" = structure(quote(f(x)), "frequency" = as.raw(c(255))), "fuzz_dot1" = NULL) | error_type | base::/: non-numeric argument to binary operator |
| deltat.zoo(structure(TRUE, "frequency" = as.raw(c(255))), character(0), "fuzz_dot1" = new.env(), "fuzz_dot2" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p })) | error_type | base::/: non-numeric argument to binary operator |
| deltat.zoo(structure(new.env(), "frequency" = as.raw(c(255))), as.name("x"), 0L, "fuzz_dot1" = function(...) NULL, "fuzz_dot2" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p })) | error_type | base::/: non-numeric argument to binary operator |
| deltat.zoo("x" = structure(local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), "frequency" = as.raw(c(255)))) | error_type | base::/: non-numeric argument to binary operator |
| deltat.zoo("x" = structure(function(...) as.name("x"), "frequency" = raw(0)), "fuzz_dot1" = as.name("x"), "fuzz_dot2" = integer(0)) | error_type | base::/: non-numeric argument to binary operator |
| deltat.zoo("x" = structure(function(...) list(NULL, function(...) raw(0)), "frequency" = raw(0)), "fuzz_dot1" = list(local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }))) | error_type | base::/: non-numeric argument to binary operator |
deltat.zoo <- function(x, ...)
{
rval <- frequency.zoo(x, ...)
if(is.null(rval)) NULL else 1/rval
}(((x: any with { frequency: dbl1<. | `I361>, any }, ...: any) -> DBL1<. | `I361>) & ((x: any with { frequency: dbl<. | `I361>, any }, ...: any) -> DBL<. | `I361>))<>| parameter | change | call | returned |
|---|---|---|---|
| x | attr:drop:frequency | deltat.zooreg("x" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p })) | (DBL & ~vec1)<> with { } |
| x | attr:drop:frequency | deltat.zooreg("x" = function(...) NULL, "fuzz_dot1" = as.name("x"), "fuzz_dot2" = function(...) list(as.name("x"), as.name("x"))) | (DBL & ~vec1)<> with { } |
| x | attr:drop:frequency | deltat.zooreg(quote(f(x)), c(-1, 1, -1, 42, 42)) | (DBL & ~vec1)<> with { } |
| x | kind:lang | deltat.zooreg("x" = quote(f(x)), "fuzz_dot1" = new.env(), "fuzz_dot2" = NULL) | (DBL & ~vec1)<> with { } |
| x | wrap | deltat.zooreg(list(structure(quote(f(x)), "frequency" = TRUE)), 0, "fuzz_dot1" = list(as.raw(c(255))), "fuzz_dot2" = as.name("x")) | (DBL & ~vec1)<> with { } |
| x | wrap | deltat.zooreg(list(structure(list(), "frequency" = 42L)), "fuzz_dot1" = local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p })) | (DBL & ~vec1)<> with { } |
| call | verdict | error |
|---|---|---|
| deltat.zooreg(structure(quote(f(x)), "frequency" = as.raw(c(255, 255))), c(-1, 1, -1, 42, 42)) | error_type | base::/: non-numeric argument to binary operator |
| deltat.zooreg("x" = structure(function(...) local({ p <- unserialize(serialize(new("externalptr"), NULL)); attributes(p) <- NULL; p }), "frequency" = as.raw(c(255))), "fuzz_dot1" = quote(f(x)), "fuzz_dot2" = function(...) as.name("x")) | error_type | base::/: non-numeric argument to binary operator |
| deltat.zooreg("x" = structure(list(NULL), "frequency" = as.raw(c(255, 0, 0, 255, 0))), "fuzz_dot1" = as.raw(c(255))) | error_type | base::/: non-numeric argument to binary operator |
deltat.zooreg <- function(x, ...)
{
1/frequency.zooreg(x, ...)
}Failure("Unsupported positional argument after a named one.")cycle.zooreg <- function(x, ...)
{
freq <- frequency(x)
ix <- as.numeric(index(x))
d <- diff(ix)
if(!identical(all.equal(freq*d, round(freq*d)), TRUE))
stop(paste(sQuote("cycle"), "not available for", sQuote("x")))
return(zoo(round((ix - floor(ix)) * freq) + 1, order.by = index(x), freq))
}is.regular — one of the package’s own names, itself untypedname: is.regular
cycle.zoo <- function(x, ...)
{
if(is.regular(x)) cycle.zooreg(x)
else stop(sQuote("x"), "is not regular")
}argument: @((dbl & ~lgl)<~@"-", . | `I372> & dbl1<~@"-", . | `I372>, null | 'ts.eps) failing call: base::<(NA_integer_, NULL)
zooreg <- function(data, start = 1, end = numeric(), frequency = 1,
deltat = 1, ts.eps = getOption("ts.eps"), order.by = NULL,
calendar = getOption("zoo.calendar", TRUE))
{
## choose frequency/deltat
if (missing(frequency)) frequency <- 1/deltat
else if(missing(deltat)) deltat <- 1/frequency
if (frequency > 1 && abs(frequency - round(frequency)) < ts.eps)
frequency <- round(frequency)
## detect if integer index is intended
intgr <- ((length(start) < 1L) || is.integer(start)) && ((length(end) < 1L) || is.integer(end))
## check data and choose default
if (missing(data) || is.null(data)) data <- NA
if(!(is.vector(data) || is.factor(data) || is.atomic(data) || is.matrix(data) || is.data.frame(data)))
stop(paste(dQuote("data"), ": attempt to define invalid zoo object"))
if(is.matrix(data) || is.data.frame(data)) data <- as.matrix(data)
## if no index (i.e., order.by) is specified: behave as ts()
## else: behave as zoo()
if (is.null(order.by)) {
if(!any(c(is.vector(data), is.factor(data), is.atomic(data), is.matrix(data), is.data.frame(data))))
stop(paste(dQuote("data"), ": attempt to define invalid zoo object"))
ndata <- NROW(data)
## convenience function
numORint <- function(x) identical(class(x), "numeric") || identical(class(x), "integer")
## choose start/end
if (length(start) > 1) start <- start[1] + (start[2] - 1)/frequency
if (length(end) > 1) end <- end[1] + (end[2] - 1)/frequency
if (missing(end)) {
ostart <- start
oend <- NULL
start <- as.numeric(start)
end <- start + (ndata - 1)/frequency
} else if(missing(start)) {
ostart <- NULL
oend <- end
end <- as.numeric(end)
start <- end - (ndata - 1)/frequency
} else{
ostart <- start
oend <- NULL
start <- as.numeric(start)
end <- as.numeric(end)
}
if (start > end) stop("start cannot be after end")
## check whether lengths of data and index match
# wrong lengths sometimes: order.by <- seq(start, end, by = deltat)
order.by <- start + seq(0, length.out = ndata) * deltat
if(isTRUE(all.equal(start * frequency, round(start * frequency), tolerance = ts.eps^2))) {
order.by <- floor(frequency * order.by + .0001)/frequency
}
## support also non-numeric indexes
if(!is.null(ostart) && !numORint(ostart))
order.by <- ostart + (order.by - start)
if(!is.null(oend) && !numORint(oend))
order.by <- oend + (order.by - end)
nobs <- length(order.by)
## nobs <- floor((end - start) * frequency + 1.01)
if (nobs != ndata) {
if(is.vector(data)) data <- rep(data, length.out = nobs)
else if(is.factor(data)) data <- factor(rep(as.character(data), length.out = nobs), labels = levels(data))
else if(is.matrix(data) || is.data.frame(data)) data <- data[rep(1:ndata, length.out = nobs), , drop = FALSE]
}
## support of calendar index (yearqtr/yearmon) for quarterly/monthly data
if(calendar && frequency %in% c(4, 12) && numORint(order.by)) {
order.by <- if(frequency == 4) as.yearqtr(order.by) else as.yearmon(order.by)
} else if(intgr) {
if(isTRUE(all.equal(order.by, round(order.by), tolerance = ts.eps^2))) order.by <- as.integer(round(order.by))
}
attr(data, "oclass") <- attr(data, "class")
attr(data, "index") <- order.by
attr(data, "frequency") <- frequency
class(data) <- c("zooreg", "zoo")
return(data)
} else {
return(zoo(data, order.by, frequency))
}
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
rev.zooreg <- function(x) { z <- as.zooreg(rev(as.zoo(x))); frequency(z) <- frequency(x); z }UseMethod — a name the prelude does not declarename: UseMethod
as.zoo <- function(x, ...)
{
UseMethod("as.zoo")
}index — one of the package’s own names, itself untypedname: index
as.zoo.default <- function(x, ...)
{
zoo(structure(x, dim = dim(x)), index(x), ...)
}zoo — one of the package’s own names, itself untypedname: zoo
as.zoo.factor <- function(x, ...)
{
zoo(x, ...)
}zoo — one of the package’s own names, itself untypedname: zoo
as.zoo.matrix <- function(x, ...)
{
zoo(x, ...)
}as.matrix — a name the prelude does not declarename: as.matrix
as.zoo.data.frame <- function(x, ...)
{
zoo(as.matrix(x), ...)
}as.matrix — a name the prelude does not declarename: as.matrix
as.zoo.fts <- function(x, ...)
{
zoo(as.matrix(x), attr(x, "dates"))
}zoo — one of the package’s own names, itself untypedname: zoo
as.zoo.irts <- function(x, ...)
{
zoo(x$value, x$time, ...)
}attr<- — a name the prelude does not declarename: attr<-
as.zoo.its <- function(x, ...)
{
index <- attr(x, "dates")
class(x) <- attr(x, "dates") <- NULL
zoo(x, index, ...)
}as.ts — a name the prelude does not declarename: as.ts
as.zoo.mcmc <- function(x, ...)
{
as.zoo(as.ts(x, ...))
}as.matrix — a name the prelude does not declarename: as.matrix
as.zoo.timeSeries <- function(x, ...) {
zoo(as.matrix(x), time(x), ...)
}coredata — one of the package’s own names, itself untypedname: coredata
as.zoo.xts <- function(x, ...) {
y <- coredata(x)
if (is.null(dim(y)) && length(y) == 0) {
y <- NULL
}
zoo(y, order.by = index(x), ...)
}UseMethod — a name the prelude does not declarename: UseMethod
as.zooreg <- function(x, frequency = NULL, ...)
{
UseMethod("as.zooreg")
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
as.zooreg.xts <- function(x, frequency = NULL, ...) {
as.zooreg(as.zoo(x, ...), frequency = frequency)
}((x: 'x, ...: any) -> 'x)<>as.zoo.zoo <- function(x, ...) xcoredata — one of the package’s own names, itself untypedname: coredata
as.vector.zoo <- function(x, mode = "any")
as.vector(coredata(x), mode = mode)coredata — one of the package’s own names, itself untypedname: coredata
as.matrix.zoo <- function(x, ...)
{
y <- as.matrix(coredata(x), ...)
if (identical(coredata(x), numeric(0))) dim (y) <- c(0, 0)
if (length(y) > 0) {
colnames(y) <- if (length(colnames(x)) > 0)
colnames(x)
else {
lab <- deparse(substitute(x), width.cutoff = 100L, nlines = 1L)
if (NCOL(x) == 1)
lab
else paste(lab, 1:NCOL(x), sep = ".")
}
} else if (nrow(y) != length(index(x))) {
dim(y) <- c(length(index(x)), 0)
}
if (!is.null(y) && nrow(y) > 0 && is.null(row.names(y)))
row.names(y) <- index2char(index(x), frequency = attr(x, "frequency"))
return(y)
}coredata — one of the package’s own names, itself untypedname: coredata
as.data.frame.zoo <- function(x, row.names = NULL, optional = FALSE, ...)
{
y <- as.data.frame(coredata(x), optional = optional, ...)
if(NCOL(x) > 0 && !optional) {
colnames(y) <- if (length(colnames(x)) > 0)
colnames(x)
else {
lab <- deparse(substitute(x), width.cutoff = 100L, nlines = 1L)
if (NCOL(x) == 1) lab
else paste(lab, 1:NCOL(x), sep = ".")
}
}
if (!is.null(row.names)) row.names(y) <- row.names
else {
tmp <- index2char(index(x), frequency = attr(x, "frequency"))
if (NROW(y) > 0 && !any(duplicated(tmp))) row.names(y) <- tmp
}
return(y)
}as.data.frame — a name the prelude does not declarename: as.data.frame
as.list.zoo <- function(x, ...) {
if (length(dim(x)) == 0) list(x)
else lapply(as.data.frame(x), zoo, index(x), attr(x, "frequency"))
}as.data.frame — a name the prelude does not declarename: as.data.frame
as.list.ts <- function(x, ...) {
if (is.matrix(x))
lapply(as.data.frame(x), ts,
start = start(x), end = end(x), freq = frequency(x))
else
list(x)
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
as.zooreg.default <- function(x, frequency = NULL, ...)
{
as.zooreg(as.zoo(x, ...), frequency = frequency)
}tsp — a name the prelude does not declarename: tsp
as.zooreg.ts <- as.zoo.ts <- function(x, frequency = NULL, ...)
{
xtsp <- tsp(x)
if(is.null(frequency)) frequency <- xtsp[3]
zooreg(coredata(x), start = xtsp[1], end = xtsp[2], frequency = frequency, ...)
} frequency — a name the prelude does not declarename: frequency
as.ts.zooreg <- function(x, ...)
{
freq <- frequency(x)
deltat <- 1/freq
tt <- as.numeric(time(x))
round. <- if(isTRUE(all.equal(c(deltat, tt), round(c(deltat, tt))))) {
function(x) floor(x + 0.5)
} else {
function(x) deltat * floor(x/deltat + 0.5)
}
tt <- round.(tt)
tt2 <- round.(seq(head(tt,1), tail(tt,1), deltat))
fill <- list(...)$fill
if(is.null(fill)) fill <- NA
xx <- merge(zoo(coredata(x), tt), zoo(, tt2), fill = fill)
ts(coredata(xx), start = tt[1], frequency = freq)
}is.regular — one of the package’s own names, itself untypedname: is.regular
as.ts.zoo <- function(x, ...)
{
if(is.regular(x)) {
attr(x, "frequency") <- frequency(x)
return(as.ts.zooreg(x, ...))
} else {
warning(paste(sQuote("x"), "does not have an underlying regularity"))
return(ts(coredata(x)))
}
}attr<- — a name the prelude does not declarename: attr<-
as.zoo.zooreg <- function(x, ...) {
attr(x, "frequency") <- NULL
class(x) <- "zoo"
return(x)
}frequency — a name the prelude does not declarename: frequency
as.zooreg.zoo <- function(x, frequency = NULL, ...)
{
if(!is.null(frequency)) {
frequency(x) <- frequency
} else {
freq <- frequency(x)
if(!is.null(freq)) {
attr(x, "frequency") <- freq
class(x) <- c("zooreg", "zoo")
} else {
warning(paste(sQuote("x"), "does not have an underlying regularity"))
x <- zooreg(coredata(x))
}
}
return(x)
}.Generic — a name the prelude does not declarename: .Generic
Ops.zoo <- function (e1, e2)
{
e <- if (missing(e2)) {
NextMethod(.Generic)
}
else if (any(nchar(.Method) == 0L)) {
NextMethod(.Generic)
}
else {
merge(e1, e2, all = FALSE, retclass = NULL)
NextMethod(.Generic)
}
if (is.null(attr(e, "index"))) {
if(!missing(e2) && nchar(.Method)[1L] == 0L) {
out <- zoo(e, index(e2), attr(e2, "frequency"))
} else {
out <- zoo(e, index(e1), attr(e1, "frequency"))
}
} else {
out <- e
}
# the next statement is a workaround for a bug in R
structure(out, class = class(out))
}as.matrix.zoo — one of the package’s own names, itself untypedname: as.matrix.zoo
t.zoo <- function(x)
t(as.matrix.zoo(x))coredata — one of the package’s own names, itself untypedname: coredata
cumsum.zoo <- function(x)
{
if (length(dim(x)) == 0) x[] <- cumsum(coredata(x))
else x[] <- apply(coredata(x), 2, cumsum)
return(x)
}coredata — one of the package’s own names, itself untypedname: coredata
cumprod.zoo <- function(x)
{
if (length(dim(x)) == 0) x[] <- cumprod(coredata(x))
else x[] <- apply(coredata(x), 2, cumprod)
return(x)
}coredata — one of the package’s own names, itself untypedname: coredata
cummin.zoo <- function(x)
{
if (length(dim(x)) == 0) x[] <- cummin(coredata(x))
else x[] <- apply(coredata(x), 2, cummin)
return(x)
}coredata — one of the package’s own names, itself untypedname: coredata
cummax.zoo <- function(x)
{
if (length(dim(x)) == 0) x[] <- cummax(coredata(x))
else x[] <- apply(coredata(x), 2, cummax)
return(x)
}MATCH — one of the package’s own names, itself untypedname: MATCH
aggregate.zoo <- function(x, by, FUN = sum, ..., regular = NULL, frequency = NULL, coredata = TRUE)
{
## index processing
my.unique <- function(x) {
ix <- MATCH(x, x) == seq_len(length(x))
x[ix]
}
if(is.function(by)) by <- by(index(x))
if(!is.list(by)) by <- list(by)
## sanity checks and option processing
stopifnot(length(time(x)) == length(by[[1]]))
if(is.null(frequency)) {
if(is.null(regular)) regular <- inherits(x, "zooreg")
} else {
if(identical(regular, FALSE)) warning(paste(sQuote("regular"), "is ignored"))
regular <- TRUE
}
## aggregate data
by_integer <- list(MATCH(by[[1]], by[[1]]))
if(coredata) {
df <- coredata(x)
} else {
df <- as.data.frame(x)
if(ncol(df) > 1L) {
for(i in 1L:ncol(df)) df[[i]] <- x[, i]
} else {
df[[1L]] <- x
}
}
df <- aggregate(df, by_integer, match.fun(FUN), ...)
if(length(unique(as.character(df[,1]))) == length(df[,1]))
row.names(df) <- df[, 1]
df <- df[, -1]
if(is.matrix(x)) df <- as.matrix(df)
## regularity processing, set up return value
ix <- my.unique(by[[1]])
rval <- zoo(df, ix[!is.na(ix)])
if(regular) {
freq <- ifelse(is.null(frequency), frequency(rval), frequency)
rval <- zoo(df, ix, freq)
}
return(rval)
}time — a name the prelude does not declarename: time
split.zoo <- function(x, f, drop = FALSE, ...) {
ix <- time(x)
xc <- coredata(x)
if (length(dim(xc)) < 2) {
lapply(split(seq_along(xc), f, drop = drop, ...),
function(ind) zoo(xc[ind], ix[ind]))
} else {
lapply(split(seq_len(nrow(xc)), f, drop = drop, ...),
function(ind) zoo(xc[ind, , drop = drop], ix[ind]))
}
}time — a name the prelude does not declarename: time
as.Date.ts <- function(x, offset = 0, ...) {
time.x <- unclass(time(x)) + offset
if (frequency(x) == 1)
as.Date(paste(time.x, 1, 1, sep = "-"))
else if (frequency(x) == 4)
as.Date(paste((time.x + .001) %/% 1, 3*(cycle(x)-1)+1, 1, sep = "-"))
else if (frequency(x) == 12)
as.Date(paste((time.x + .001) %/% 1, cycle(x), 1, sep = "-"))
else
stop("unable to convert ts time to Date class")
}as.zooreg — one of the package’s own names, itself untypedname: as.zooreg
as.zoo.tis <- function(x, class = "ti", ...) {
if (class == "ti") {
as.zoo(as.zooreg(x, class = "ti", ...))
} else if (class == "numeric") {
zoo(tis::stripTis(x), time(tis::ti(x), offset = 0))
} else {
asFun <- paste("as", class, sep = ".")
zoo(tis::stripTis(x), do.call(asFun, list(tis::POSIXct(tis::ti(x), offset = 0, tz = "GMT"))), ...)
}
}tis::stripTis — a name the prelude does not declarename: tis::stripTis
as.zooreg.tis <- function(x, frequency = NULL, class = "ti", ...) {
if (class == "ti") zooreg(tis::stripTis(x), start = start(x), ...)
else as.zooreg(as.zoo(x, class = class, ...), frequency = frequency)
}coredata — one of the package’s own names, itself untypedname: coredata
barplot.zoo <- function(height, names.arg = NULL, ...)
{
x <- coredata(height)
if(!is.null(dim(x))) x <- t(x)
if(is.null(names.arg)) names.arg <- index2char(index(height))
barplot(x, names.arg = names.arg, ...)
}coredata — one of the package’s own names, itself untypedname: coredata
boxplot.zoo <- function(x, ...) boxplot(coredata(x), ...)NROW — a name the prelude does not declarename: NROW
fortify.zoo <- function(model, data, names = c("Index", "Series", "Value"),
melt = FALSE, sep = NULL, ...)
{
if (!is.null(sep) && !melt) stop("Cannot specify sep if melt = FALSE")
## dimensions
n <- NROW(model)
k <- NCOL(model)
## dots only named data.frame arguments
dots <- list(...)
dots <- dots[names(dots) %in%
c("row.names", "check.rows", "check.names", "fix.empty.names", "stringsAsFactors")]
## series labels
lab <- colnames(model)
if(is.null(lab)) lab <- rep.int(deparse(substitute(model)), k)
lab <- make.unique(lab)
## return data names
nm <- c("Index", "Series", "Value")
if(!is.null(names(names))) names <- names[nm]
if(is.list(names)) {
names(names) <- nm
for(i in 1L:3L) if(is.null(names[[i]]) || anyNA(names[[i]])) names[[i]] <- nm[i]
nm <- unlist(names)
} else {
names <- rep_len(names, 3L)
nm[!is.na(names)] <- names[!is.na(names)]
}
## either long format (melt = TRUE) or wide format (melt = FALSE)
if(melt) {
df <- if(k == 1L) {
do.call("data.frame", c(
list(index(model), factor(rep.int(1, n), labels = lab), coredata(model)),
dots))
} else {
do.call("data.frame", c(
list(index(model)[rep.int(1:n, k)],
factor(rep(1:k, each = n), levels = 1:k, labels = lab),
as.vector(coredata(model))),
dots))
}
if (!is.null(sep)) {
df <- data.frame(df[1L],
do.call("rbind", strsplit(as.character(df[[2L]]), ".", fixed = TRUE)),
df[3L])
}
nl <- length(nm)
names(df) <- c(nm[1L], make.unique(rep_len(nm[-c(1L, nl)], ncol(df) - 2L)), nm[nl])
} else {
df <- cbind(
do.call("data.frame", c(list(index(model)), dots)),
coredata(model))
names(df) <- c(nm[1L], lab)
}
return(df)
}substitute — a name the prelude does not declarename: substitute
autoplot.zoo <- function(object, geom = "line", facets, ...)
{
## convert to data.frame (and assure correct label
## processing by fortify.zoo)
lab <- deparse(substitute(object))
if(NCOL(object) == 1L) {
if(is.null(dim(object))) dim(object) <- c(NROW(object), 1L)
if(is.null(colnames(object))) colnames(object) <- lab
}
if(is.null(colnames(object))) colnames(object) <- paste(lab, 1:NCOL(object), sep = ".")
df <- fortify.zoo(object, melt = TRUE)
## default for facets
single <- nlevels(df$Series) == 1L
if(missing(facets)) {
auto <- TRUE
facets <- if(single) NULL else Series ~ .
} else {
auto <- FALSE
}
## process defaults as for old qplot-based interface
if(is.character(geom)) geom <- get(paste0("geom_", geom), asNamespace("ggplot2"))
if(inherits(facets, "formula")) facets <- ggplot2::facet_grid(facets)
## "fake" variables for nonstandard evaluation
Index <- Value <- Series <- NULL
## call qplot
gg <- if(single | (!is.null(facets) & auto)) {
ggplot2::ggplot(df, ggplot2::aes(x = Index, y = Value, ...)) + geom() + facets + ggplot2::ylab(if(single) levels(df$Series) else "") + ggplot2::xlab("Index")
} else {
ggplot2::ggplot(df, ggplot2::aes(x = Index, y = Value, group = Series, colour = Series, ...)) + geom() + facets + ggplot2::ylab("") + ggplot2::xlab("Index")
}
return(gg)
}Series — a name the prelude does not declarename: Series
facet_free <- function (facets = Series ~ ., margins = FALSE, scales = "free_y", ...) {
ggplot2::facet_grid(facets, margins = margins, scales = scales, ...)
}scales::pretty_breaks — a name the prelude does not declarename: scales::pretty_breaks
yearmon_trans <- function(format = "%b %Y", n = 5) {
breaks. <- function(x) as.yearmon(scales::pretty_breaks(n)(x))
format. <- function(x) format(x, format = format)
scales::trans_new("yearmon", transform = as.numeric, inverse = as.yearmon,
breaks = breaks., format = format.)
}Failure("Unsupported argument after an ellipsis.")scale_x_yearmon <- function(..., format = "%b %Y", n = 5) {
ggplot2::scale_x_continuous(..., transform = yearmon_trans(format, n))
}Failure("Unsupported argument after an ellipsis.")scale_y_yearmon <- function(..., format = "%b %Y", n = 5) {
ggplot2::scale_y_continuous(..., transform = yearmon_trans(format, n))
}scales::pretty_breaks — a name the prelude does not declarename: scales::pretty_breaks
yearqtr_trans <- function(format = "%Y-%q", n = 5) {
breaks. <- function(x) as.yearqtr(scales::pretty_breaks(n)(x))
format. <- function(x) zoo::format.yearqtr(x, format = format)
scales::trans_new("yearqtr", transform = as.numeric, inverse = as.yearqtr,
breaks = breaks., format = format.)
}Failure("Unsupported argument after an ellipsis.")scale_x_yearqtr <- function(..., format = "%Y-%q", n = 5) {
ggplot2::scale_x_continuous(..., transform = yearqtr_trans(format, n))
}Failure("Unsupported argument after an ellipsis.")scale_y_yearqtr <- function(..., format = "%Y-%q", n = 5) {
ggplot2::scale_y_continuous(..., transform = yearqtr_trans(format, n))
}| parameter | change | call | returned |
|---|---|---|---|
| x | drop | scale_type.yearqtr() | (CHR & ~vec1)<> with { } |
scale_type.yearqtr <- function(x) c("yearqtr", "continuous")| parameter | change | call | returned |
|---|---|---|---|
| x | drop | scale_type.yearmon() | (CHR & ~vec1)<> with { } |
scale_type.yearmon <- function(x) c("yearmon", "continuous")Negate — a name the prelude does not declarename: Negate
rbind.zoo <- function(..., deparse.level = 1)
{
args <- Filter(Negate(is.null), list(...))
indexes <- do.call("c", unname(lapply(args, index)))
my.table <- function(x) {
ix <- ORDER(x)
x <- x[ix]
table(MATCH(x,x))
}
if(max(my.table(indexes)) > 1L) stop("indexes overlap")
if(any(sapply(args, function(x) is.null(dim(x)) && length(x) == 0L && length(index(x)) > 0L)))
stop("zero-length vectors with non-zero-length index are not allowed")
ncols <- sapply(args, NCOL)
if(!all(ncols == ncols[1L])) stop("number of columns differ")
## process colnames() if any
nams <- lapply(args, colnames)
namsNULL <- sapply(nams, is.null)
if(all(namsNULL)) namsOK <- TRUE else {
if(sum(namsNULL) > 0L) namsOK <- FALSE else {
nam1 <- nams[[1L]]
namsID <- sapply(nams, function(x) identical(x, nam1))
if(all(namsID)) namsOK <- TRUE else {
namsSORT <- sapply(nams, function(x) identical(sort(x), sort(nam1)))
if(!all(namsSORT)) namsOK <- FALSE else {
namsOK <- TRUE
for(i in which(!namsID)) args[[i]] <- args[[i]][,nam1]
}
}
}
}
if(!namsOK) warning("column names differ")
## collect data
argsdata <- lapply(args, coredata)
## (special case: rbinding of vectors with one-column matrices)
nulldim <- sapply(argsdata, function(a) is.null(dim(a)))
if(ncols[1L] == 1L) {
if(nulldim[1] & any(!nulldim)) {
argsdata <- lapply(argsdata, function(a) if(is.null(dim(a))) a else a[,1, drop = TRUE])
nulldim <- rep(TRUE, length(nulldim))
}
if(!nulldim[1] & any(nulldim)) {
argsdata <- lapply(argsdata, function(a) if(is.null(dim(a))) as.matrix(a) else a)
nulldim <- rep(FALSE, length(nulldim))
}
}
if((ncols[1L] > 1L) | !all(nulldim))
rval <- zoo(do.call("rbind", argsdata), indexes)
else
rval <- zoo(do.call("c", argsdata), indexes)
freq <- if(!("zooreg" %in% unlist(sapply(args, class)))) NULL
else {
freq <- c(frequency(rval), unlist(sapply(args, frequency)))
if((length(freq) == (length(args)+1L)) &&
identical(all.equal(max(freq)/freq, round(max(freq)/freq)), TRUE))
max(freq) else NULL
}
if(!is.null(freq)) {
attr(rval, "frequency") <- freq
class(rval) <- c("zooreg", class(rval))
}
return(rval)
}rbind.zoo — one of the package’s own names, itself untypedname: rbind.zoo
c.zoo <- function(...) {
rbind.zoo(...)
}Invalid_argument("Variable ..._5 is already bound.")merge.zoo <- function(..., all = TRUE, fill = NA, suffixes = NULL, check.names = FALSE, retclass = c("zoo", "list", "data.frame"), drop = TRUE, sep = ".")
{
if (!is.null(retclass)) retclass <- match.arg(retclass)
# cl are calls to the args and args is a list of the arguments
cl <- as.list(match.call())
cl[[1]] <- cl$all <- cl$fill <- cl$retclass <- cl$suffixes <- cl$check.names <- cl$drop <- cl$sep <- NULL
args <- list(...)
parent <- parent.frame()
is.plain <- function(x)
all(class(x) %in% c("array", "integer", "numeric", "factor", "matrix", "logical", "character"))
is.scalar <- function(x) is.plain(x) && length(x) == 1
# ensure all ... plain args are of length 1 or have same NROW as arg 1
stopifnot(all(sapply(args, function(x) is.zoo(x) || !is.plain(x) ||
(is.plain(x) && (NROW(x) == NROW(args[[1]]) || is.scalar(x))))))
scalars <- sapply(args, is.scalar)
if(!is.zoo(args[[1]])) args[[1]] <- as.zoo(args[[1]])
for(i in seq_along(args))
if (is.plain(args[[i]]))
args[[i]] <- zoo(args[[i]], index(args[[1]]), attr(args[[1]], "frequency"))
else if (!is.zoo(args[[i]]))
args[[i]] <- as.zoo(args[[i]])
## retain frequency if all series have integer multiples of the same frequency
## and at least one of the original objects is a "zooreg" object
freq <- if(!("zooreg" %in% unlist(sapply(args, class)))) NULL
else {
freq <- unlist(sapply(args, frequency))
if((length(freq) == length(args)) &&
identical(all.equal(max(freq)/freq, round(max(freq)/freq)), TRUE))
max(freq) else NULL
}
# use argument names if suffixes not specified
if (is.null(suffixes)) {
makeNames <- function(l) {
nm <- names(l)
fixup <- if (is.null(nm))
seq_along(l)
else nm == ""
dep <- sapply(l[fixup], function(x) deparse(x)[1])
if (is.null(nm))
return(dep)
if (any(fixup))
nm[fixup] <- dep
nm
}
suffixes <- makeNames(as.list(substitute(list(...)))[-1])
}
if (length(suffixes) != length(cl)) {
warning("length of suffixes and does not match number of merged objects")
suffixes <- rep(suffixes, length.out = length(cl))
}
# extend all to a length equal to the number of args
all <- rep(as.logical(all), length.out = length(cl))
## check indexes:
indexlist <- lapply(args, index)
## 1. for non-unique entries
index_duplicates <- function(x) length(unique(MATCH(x, x))) < length(x)
if(any(sapply(indexlist, index_duplicates)))
stop("series cannot be merged with non-unique index entries in a series")
## 2. for differing classes
indexclasses <- sapply(indexlist, function(x) class(x)[1])
if (!all(indexclasses == indexclasses[1L])) {
warning(paste("Index vectors are of different classes:",
paste(indexclasses, collapse = " ")))
if(all(indexclasses %in% c("numeric", "integer"))) {
indexlist <- lapply(indexlist, as.numeric)
} else if(all(vapply(indexlist, function(e) inherits(e, "Date") || is.numeric(e), NA))) {
indexlist <- lapply(indexlist, as.Date)
}
}
# fn to get the unique elements in x, in sorted order, using only
# [, match, length and order
sort.unique <- function(x) {
ix <- MATCH(x, x) == seq_len(length(x))
x <- x[ix]
ix <- ORDER(x)
x[ix]
}
# fn to get intersection of each element in list of lists
intersect.list <- function(list) {
my.table <- function(x) {
ix <- ORDER(x)
x <- x[ix]
table(MATCH(x, x))
}
union <- do.call("c", unname(list))
sort.unique(union)[which(my.table(union) == length(list))]
}
indexintersect <- intersect.list(indexlist)
# get the indexes of the final answer which is the union of
# all indexes of args corresponding to all=TRUE with the intersection
# of all indexes
indexunion <- do.call("c", unname(indexlist[all]))
indexes <- if(is.null(indexunion)) indexintersect
else sort.unique(c(indexunion, indexintersect))
# previously, we used to do:
# if (is.null(indexunion)) indexunion <- do.call("c", indexlist)[0]
# indexes <- sort.unique(c(indexunion, indexintersect))
## check whether resulting objects still got the same frequency
if(!is.null(freq)) {
freq <- c(frequency(zoo(,indexes)), freq)
freq <- if((length(freq) == 2) && identical(all.equal(max(freq)/freq, round(max(freq)/freq)), TRUE))
max(freq) else NULL
}
# the f function does the real work
# it takes a zoo object, a, and fills in a matrix corresponding to
# indexes with the values in a. ret.zoo is TRUE if it is to return
# a zoo object. If ret.zoo is FALSE it simply returns with the matrix
# just calculated.
# match0 is convenience wrapper for MATCH with nomatch=0 default
match0 <- function(a, b, nomatch = 0, ...) MATCH(a, b, nomatch = nomatch, ...)
f <- if (any(all)) {
function(a, ret.zoo = TRUE) {
if (length(a) == 0 && length(dim(a)) == 0)
return(if(ret.zoo) {
rval <- zoo(, indexes)
attr(rval, "frequency") <- freq
if(!is.null(freq)) class(rval) <- c("zooreg", class(rval))
rval
} else numeric())
z <- matrix(fill, length(indexes), NCOL(a))
if (length(dim(a)) > 0)
z[match0(index(a), indexes), ] <- a[match0(indexes, index(a)), , drop = FALSE]
else {
z[match0(index(a), indexes), ] <- a[match0(indexes, index(a))]
z <- z[, 1, drop=TRUE]
}
if (ret.zoo) {
z <- zoo(z, indexes)
attr(z, "oclass") <- attr(a, "oclass")
attr(z, "levels") <- attr(a, "levels")
attr(z, "frequency") <- freq
if(!is.null(freq)) class(z) <- c("zooreg", class(z))
}
return(z)
}
} else {
# if all contains only FALSE elements then the following f is used
# instead of the prior f for performance purposes. If all contains
# only FALSE then the resulting index is the intersection of the
# index of each argument so we can just return a[index] or a[index,].
# Also if we are not to return a zoo object then unclass it prior to return.
function(a, ret.zoo = TRUE) {
if (!ret.zoo) class(a) <- NULL
if (length(dim(a)) == 0) {
if (length(a) == 0) {
rval <- if(ret.zoo) zoo(, indexes) else numeric()
} else
rval <- as.zoo(a[match0(indexes, attr(a, "index"))])
} else
rval <- as.zoo(a[match0(indexes, attr(a, "index")), , drop=FALSE])
if(is.zoo(rval) && !is.null(freq)) {
attr(rval, "frequency") <- freq
class(rval) <- unique(c("zooreg", class(rval)))
}
return(rval)
}
}
# if retclass is NULL do not provide a return value but instead
# update each argument that is a variable, i.e. not an expression,
# in place.
if (is.null(retclass)) {
for(vn in cl) {
if (is.name(vn))
tryCatch(
eval(substitute(v <- f(v), list(f = f, v = vn)), parent),
condition = function(x) {}
)
}
invisible(return(NULL))
}
# apply f to each arg, put result of doing this on all args in list rval
# and then cbind that list together to produce the required matrix
rval <- lapply(args, f, ret.zoo = retclass %in% c("list", "data.frame"))
## have commented this next line out. Is it needed?
# for(i in which(scalars)) rval[[i]] <- rval[[i]][] <- zoo(coredata(rval[[i]])[1], index(rval[[1]]), freq)
names(rval) <- suffixes
if (retclass == "list") {
return(rval)
}
if (retclass == "data.frame") {Failure("Unsupported argument after an ellipsis.")cbind.zoo <- function(..., all = TRUE, fill = NA, suffixes = NULL, drop = FALSE, sep = ".")
{
merge.zoo(..., all = all, fill = fill, suffixes = suffixes, retclass = "zoo", drop = drop, sep = sep)
}UseMethod — a name the prelude does not declarename: UseMethod
na.trim <- function(object, ...) UseMethod("na.trim")complete.cases — a name the prelude does not declarename: complete.cases
na.trim.default <- function (object, sides = c("both", "left", "right"),
is.na = c("any", "all"), maxgap = Inf, ...)
{
is.na <- match.arg(is.na, c("any", "all"))
nisna <- if (is.na == "any" || length(dim(object)) < 2L) {
complete.cases(object)
} else rowSums(!is.na(object)) > 0
rlength <- function(x) if(all(!x)) length(x) else min(which(x)) - 1L
idx <- switch(match.arg(sides),
left = {
idx0 <- cumsum(nisna) > 0
idx0 | rlength(idx0) > maxgap
},
right = {
idx0 <- cumsum(rev(nisna) > 0) > 0
rev(idx0) | rlength(idx0) > maxgap
},
both = {
idx0l <- cumsum(nisna) > 0
idx0r <- cumsum(rev(nisna) > 0) > 0
(idx0l | rlength(idx0l) > maxgap) & (rev(idx0r) | rlength(idx0r) > maxgap)
}
)
if (length(dim(object)) < 2L)
object[idx]
else
object[idx,, drop = FALSE]
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
na.trim.ts <- function (object, ...)
{
as.ts(na.trim(as.zoo(object), ...))
}UseMethod — a name the prelude does not declarename: UseMethod
na.approx <- function(object, ...) UseMethod("na.approx")rle — a name the prelude does not declarename: rle
.fill_short_gaps <- function(x, fill, maxgap) {
if (maxgap <= 0)
return(x)
if (maxgap >= length(x))
return(fill)
naruns <- rle(is.na(x))
naruns$values[naruns$lengths > maxgap] <- FALSE
naok <- inverse.rle(naruns)
x[naok] <- fill[naok]
return(x)
}Invalid_argument("Variable ..._5 is already bound.")na.approx.default <- function(object, x = index(object), xout = x, ..., na.rm = TRUE, maxgap = Inf, along) {
if (!missing(along)) {
warning("along to be deprecated - use x instead")
if (missing(x)) x <- along
}
na.approx.vec <- function(x, y, xout = x, ...) {
na <- is.na(y)
if(sum(!na) < 2L) {
## approx() cannot be applied here, hence simply:
yf <- rep.int(NA, length(xout))
mode(yf) <- mode(y)
if(any(!na)) {
if(x[!na] %in% xout) {
yf[xout == x[!na]] <- y[!na]
}
}
return(yf)
}
if(all(!na) && (length(xout) > maxgap) && !all(xout %in% x)) {
## for maxgap to work correctly 'y' has to contain
## actual NAs and be expanded to the full x-index
xf <- sort(unique(c(x, xout)))
yf <- rep.int(NA, length(xf))
yf[MATCH(x, xf)] <- y
x <- xf
y <- yf
}
yf <- approx(x[!na], y[!na], xout, ...)$y
if (maxgap < length(y)) {
## construct a series like y but with only gaps > maxgap
## (actual values don't matter as we only use is.na(ygap) below)
ygap <- .fill_short_gaps(y, seq_along(y), maxgap = maxgap)
## construct y values at 'xout', keeping NAs from ygap
## (using indexing, as approx() does not allow NAs to be propagated)
ix <- approx(x, seq_along(y), xout, ...)$y
yx <- ifelse(is.na(ygap[floor(ix)] + ygap[ceiling(ix)]), NA, yf)
yx
} else {
yf
}
}
if (!identical(length(x), length(index(object)))) {
stop("x and index must have the same length")
}
x. <- as.numeric(x)
if (missing(xout) || is.null(xout)) xout <- x.
xout. <- as.numeric(xout)
object. <- coredata(object)
result <- if (length(dim(object.)) < 2) {
na.approx.vec(x., coredata(object.), xout = xout., ...)
} else {
apply(coredata(object.), 2, na.approx.vec, x = x., xout = xout., ...)
}
if (na.rm) {
result <- na.trim(result, is.na = "all", maxgap = maxgap)
}
result
}Failure("Unsupported argument after an ellipsis.")na.approx.zoo <- function(object, x = index(object), xout, ..., na.rm = TRUE, maxgap = Inf, along) {
if (!missing(along)) {
warning("along to be deprecated - use x instead")
if (missing(x)) x <- along
}
missing.xout <- missing(xout) || is.null(xout)
if (is.function(x)) x <- x(index(object))
if (!missing.xout && is.function(xout)) xout <- xout(index(object))
order.by <- if (missing.xout) index(object) else xout
xout <- if (missing.xout) x else xout
if (missing.xout || identical(xout, index(object))) {
result <- object
} else {
object.x <- object
if (!identical(class(x), class(xout))) {
index(object.x) <- as.numeric(x)
xout <- as.numeric(xout)
} else {
index(object.x) <- x
}
objectm <- merge(object.x, zoo(, xout))
if (length(dim(objectm)) == 2) colnames(objectm) <- colnames(object)
result <- window(objectm, index. = xout)
}
result[] <- na.approx.default(object, x = x, xout = xout, na.rm = FALSE, ..., maxgap = maxgap)
if ((!missing(order.by) && !is.null(order.by)) || !missing.xout) {
index(result) <- order.by
}
if (na.rm) {
result <- na.trim(result, is.na = "all", maxgap = maxgap)
}
result
}na.approx — one of the package’s own names, itself untypedname: na.approx
na.approx.zooreg <- function(object, ...) {
object. <- structure(object, class = setdiff(class(object), "zooreg"))
as.zooreg(na.approx(object., ...))
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
na.approx.ts <- function(object, ...) {
as.ts(na.approx(as.zoo(object), ...))
}UseMethod — a name the prelude does not declarename: UseMethod
na.StructTS <- function(object, ...) UseMethod("na.StructTS")StructTS — a name the prelude does not declarename: StructTS
na.StructTS.ts <- function(object, ..., na.rm = FALSE, maxgap = Inf)
{
na.StructTS.0 <- function(y) {
yf <- y
isna <- is.na(y)
yf[isna] <- rowSums(tsSmooth(StructTS(y))[,-2])[isna]
.fill_short_gaps(y, yf, maxgap = maxgap)
}
object[] <- if (length(dim(object)) == 0) na.StructTS.0(object)
else apply(object, 2, na.StructTS.0)
if (na.rm) na.trim(object, is.na = "all") else object
}Failure("Unsupported argument after an ellipsis.")na.StructTS.zoo <- function(object, ..., na.rm = FALSE, maxgap = Inf) {
z <- na.StructTS(as.ts(object), ..., na.rm = FALSE, maxgap = maxgap)
z <- as.zoo(z)
time(z) <- time(object)
if (na.rm) na.trim(z, is.na = "all") else z
}UseMethod — a name the prelude does not declarename: UseMethod
na.aggregate <- function(object, ...) UseMethod("na.aggregate")mean — a name the prelude does not declarename: mean
na.aggregate.default <- function(object, by = 1, ..., FUN = mean, na.rm = FALSE, maxgap = Inf)
{
if (is.function(by)) by <- by(time(object), ...)
## applied to each aggregated group in each series:
f <- function(x)
replace(x, is.na(x), FUN(x[!is.na(x)]))
na.aggregate.0 <- function(y) {
yf <- ave(y, by, FUN = f)
.fill_short_gaps(y, yf, maxgap = maxgap)
}
object[] <- if (length(dim(object)) == 0) na.aggregate.0(object)
else apply(object, 2, na.aggregate.0)
if (na.rm) na.trim(object, is.na = "all") else object
}lengths — a name the prelude does not declarename: lengths
na.fill0 <- function(object, fill, ix = !is.na(object))
{
if (length(object) == 0L) {
object
} else if (length(fill) == 0L || sum(lengths(as.list(fill))) == 0L) {
structure(object[ix], na.action = which(!ix))
} else if (length(fill) == 1L) {
if (identical(as.list(fill)[[1L]], "extend"))
stop("fill cannot be 'extend'")
if (!is.logical(ix)) ix <- seq_along(object) %in% ix
replace(object, !ix, as.list(fill)[[1L]])
} else {
fill <- rep(as.list(fill), length.out = 3L)
if (identical(fill[[2L]], "extend"))
stop("fill[[2L]] cannot be 'extend'")
ix <- if (is.logical(ix)) rep(ix, length.out = length(object)) else seq_along(object) %in% ix
wx <- which(ix)
if (length(wx) == 0L) {
object[] <- fill[[2L]]
object
} else {
rng <- range(wx)
if (identical(fill[[1L]], "extend")) fill[[1L]] <- object[rng[1L]]
if (identical(fill[[3L]], "extend")) fill[[3L]] <- object[rng[2L]]
fill_lens <- lengths(fill)
pre <- seq_along(ix) < rng[1L]
post <- seq_along(ix) > rng[2L]
if (fill_lens[2L]) object[!ix] <- fill[[2L]]
if (fill_lens[1L]) object[pre] <- fill[[1L]]
if (fill_lens[3L]) object[post] <- fill[[3L]]
omit <- (pre & !fill_lens[1L]) |
(!pre & !post & !ix & !fill_lens[2L]) |
(post & !fill_lens[3L])
object <- object[!omit]
if (sum(omit)) structure(object, na.action = which(omit)) else object
}
}
}UseMethod — a name the prelude does not declarename: UseMethod
na.fill <- function(object, fill, ...) UseMethod("na.fill")na.fill.zoo <- function(object, fill, ix, ...) {
if (length(dim(object)) == 2 && NCOL(object) > 1) {
ixmiss <- missing(ix)
L <- lapply(1:NCOL(object),
function(i) {
if (ixmiss) ix <- !is.na(object[,i])
na.fill(object[,i], fill, ix, ...)
})
out <- do.call("merge", c(L, all = FALSE))
colnames(out) <- colnames(object)
return(out)
}
if (missing(ix)) ix <- !is.na(object)
if ((is.logical(ix) && any(ix)) || (!is.logical(ix) && length(ix))) {
n <- length(object)
# integer indexes for output points which are present
wix <- if (is.logical(ix)) which(ix) else ix
# min and max integer index
wx.min <- head(wix, 1)
wx.max <- tail(wix, 1)
# similar to wrng <- wx.min:wx.max
wrng <- seq(wx.min, length.out = wx.max - wx.min + 1)
# recycle to length 3
fill <- rep(as.list(fill), length.out = 3)
# we will be coercing fill values to the class of coredata(data).
# This allows fill=c("extend", NA) to work even though NA is coerced to
# a character NA.
as.cls <- if (is.integer(coredata(object))) {
as.integer
} else if(is.numeric(coredata(object))) {
as.numeric
} else if(is.character(coredata(object))) {
as.character
} else {
as.logical
}
fill <- lapply(fill, function(x) if (is.character(x) &&
pmatch(x, "extend", nomatch = 0)) "extend" else as.cls(x))
# fill points on left
if (length(fill[[1]]) > 0)
if (!is.null(fill[[1]])) object[seq_len(wx.min - 1)] <-
if (is.character(fill[[1]]) && !is.na(fill[[1]]) && fill[[1]] == "extend")
object[[wx.min]] else fill[[1]]
# fill intermediate points
# - this is for zoo method, for zooreg method it would be possible to
# perform linear interpolation in proportion to time rather than
# in proportion to the integer index
if (length(fill[[2]]) > 0) {
if (is.character(fill[[2]]) && !is.na(fill[[2]]) && fill[[2]] == "extend") object[wrng] <-
# as.list(approx(wix, unlist(object[wix]), xout = wrng)$y)
approx(wix, unlist(object[wix]), xout = wrng)$y
else object[intersect(which(!ix), wrng)] <- fill[[2]]
}
# fill points on right
if (length(fill[[3]]) > 0)
object[seq(wx.max + 1, length.out = n - wx.max)] <-
if (is.character(fill[[3]]) && !is.na(fill[[3]]) && fill[[3]] == "extend")
object[[wx.max]] else fill[[3]]
keep <- seq_len(n)
if (length(fill[[1]]) == 0) keep <- unique(pmax(wx.min, keep))
if (length(fill[[2]]) == 0) {
wrng <- seq(wx.min, length.out = wx.max - wx.min + 1)
keep <- setdiff(keep, intersect(which(!ix), wrng))
}
if (length(fill[[3]]) == 0) keep <- unique(pmin(wx.max, keep))
return(object[keep, , drop = is.null(dim(object))])
} else if(length(fill)) {
fill <- unlist(fill[1])[1]
object[is.na(object)] <- if(!is.na(fill) && fill == "extend") NA else fill
return(object)
}
}zoo — one of the package’s own names, itself untypedname: zoo
na.fill.default <- function(object, fill, ix, ...) {
coredata(na.fill(zoo(object), fill, ix, ...))
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
na.fill.ts <- function(object, fill, ix, ...) {
as.ts(na.fill(as.zoo(object), fill, ix, ...))
}variable: coredata expected: null given: ff<> | tt<> expression may be: FALSE
na.locf0 <- function(object, fromLast = FALSE, maxgap = Inf, coredata = NULL) {
if(is.null(coredata)) coredata <- inherits(object, "ts") || inherits(object, "zoo") || inherits(object, "its") || inherits(object, "irts")
if(coredata) {
x <- object
object <- if (fromLast) rev(coredata(object)) else coredata(object)
} else {
if(fromLast) object <- rev(object)
}
ok <- which(!is.na(object))
if(is.na(object[1L])) ok <- c(1L, ok)
gaps <- diff(c(ok, length(object) + 1L))
object <- if(any(gaps > maxgap)) {
.fill_short_gaps(object, rep(object[ok], gaps), maxgap = maxgap)
} else {
rep(object[ok], gaps)
}
if (fromLast) object <- rev(object)
if(coredata) {
x[] <- object
return(x)
} else {
return(object)
}
}UseMethod — a name the prelude does not declarename: UseMethod
na.locf <- function(object, na.rm = TRUE, ...)
UseMethod("na.locf")na.approx — one of the package’s own names, itself untypedname: na.approx
na.locf.default <- function(object, na.rm = TRUE, fromLast, rev, maxgap = Inf, rule = 2, ...) {
L <- list(...)
if ("x" %in% names(L) || "xout" %in% names(L)) {
if (!missing(fromLast)) {
stop("fromLast not supported if x or xout is specified")
}
return(na.approx(object, na.rm = na.rm,
maxgap = maxgap, method = "constant", rule = rule, ...))
}
if (!missing(rev)) {
warning("na.locf.default: rev= deprecated. Use fromLast= instead.")
if (missing(fromLast)) fromLast <- rev
} else if (missing(fromLast)) fromLast <- FALSE
rev <- base::rev
object[] <- if (length(dim(object)) == 0)
na.locf0(object, fromLast = fromLast, maxgap = maxgap)
else
apply(object, length(dim(object)), na.locf0, fromLast = fromLast, maxgap = maxgap)
if (na.rm) na.trim(object, is.na = "all") else object
}na.locf0 — one of the package’s own names, itself untypedname: na.locf0
na.locf.data.frame <- function(object, na.rm = TRUE, fromLast = FALSE, maxgap = Inf, ...)
{
object[] <- lapply(object, na.locf0, fromLast = fromLast, maxgap = maxgap)
if (na.rm) na.omit(object) else object
}apply — a name the prelude does not declarename: apply
na.contiguous.data.frame <-
na.contiguous.zoo <- function(object, ...)
{
if (length(dim(object)) == 2)
good <- apply(!is.na(object), 1, all)
else good <- !is.na(object)
if (!sum(good))
stop("all times contain an NA")
tt <- cumsum(!good)
ln <- sapply(0:max(tt), function(i) sum(tt == i))
seg <- (seq_along(ln)[ln == max(ln)])[1] - 1
keep <- (tt == seg)
st <- min(which(keep))
if (!good[st])
st <- st + 1
en <- max(which(keep))
omit <- integer(0)
n <- NROW(object)
if (st > 1)
omit <- c(omit, 1:(st - 1))
if (en < n)
omit <- c(omit, (en + 1):n)
cl <- class(object)
if (length(omit)) {
object <- if (length(dim(object)))
object[st:en, ]
else object[st:en]
attr(omit, "class") <- "omit"
attr(object, "na.action") <- omit
if (!is.null(cl))
class(object) <- cl
}
object
}na.contiguous — a name the prelude does not declarename: na.contiguous
na.contiguous.list <- function(object, ...)
lapply(object, na.contiguous)UseMethod — a name the prelude does not declarename: UseMethod
na.spline <- function(object, ...) UseMethod("na.spline")Invalid_argument("Variable ..._5 is already bound.")na.spline.default <- function(object, x = index(object), xout = x, ..., na.rm = TRUE, maxgap = Inf, along) {
if (!missing(along)) {
warning("along to be deprecated - use x instead")
if (missing(x)) x <- along
}
na.spline.vec <- function(x, y, xout = x, ...) {
na <- is.na(y)
if(sum(!na) < 1L) {
## splinefun() cannot be applied here, hence simply:
yf <- rep.int(NA, length(xout))
mode(yf) <- mode(y)
if(any(!na)) {
if(x[!na] %in% xout) {
yf[xout == x[!na]] <- y[!na]
}
}
return(yf)
}
if(all(!na) && (length(xout) > maxgap) && !all(xout %in% x)) {
## for maxgap to work correctly 'y' has to contain
## actual NAs and be expanded to the full x-index
xf <- sort(unique(c(x, xout)))
yf <- rep.int(NA, length(xf))
yf[MATCH(x, xf)] <- y
x <- xf
y <- yf
}
yf <- splinefun(x[!na], y[!na], ...)(xout)
if (maxgap < length(y)) {
## construct a series like y but with only gaps > maxgap
## (actual values don't matter as we only use is.na(ygap) below)
ygap <- .fill_short_gaps(y, seq_along(y), maxgap = maxgap)
## construct y values at 'xout', keeping NAs from ygap
## (using indexing, as approx() does not allow NAs to be propagated)
ix <- splinefun(x, seq_along(y), ...)(xout)
yx <- ifelse(is.na(ygap[floor(ix)] + ygap[ceiling(ix)]), NA, yf)
yx
} else {
yf
}
}
if (!identical(length(x), length(index(object)))) {
stop("x and index must have the same length")
}
x. <- as.numeric(x)
if (missing(xout) || is.null(xout)) xout <- x.
xout. <- as.numeric(xout)
object. <- coredata(object)
result <- if (length(dim(object.)) < 2) {
na.spline.vec(x., coredata(object.), xout = xout., ...)
} else {
apply(coredata(object.), 2, na.spline.vec, x = x., xout = xout., ...)
}
if (na.rm) {
result <- na.trim(result, is.na = "all", maxgap = maxgap)
}
result
}Failure("Unsupported argument after an ellipsis.")na.spline.zoo <- function(object, x = index(object), xout, ..., na.rm = TRUE, maxgap = Inf, along) {
if (!missing(along)) {
warning("along to be deprecated - use x instead")
if (missing(x)) x <- along
}
missing.xout <- missing(xout) || is.null(xout)
if (is.function(x)) x <- x(index(object))
if (!missing.xout && is.function(xout)) xout <- xout(index(object))
order.by <- if (missing.xout) index(object) else xout
xout <- if (missing.xout) x else xout
if (missing.xout || identical(xout, index(object))) {
result <- object
} else {
object.x <- object
if (!identical(class(x), class(xout))) {
index(object.x) <- as.numeric(x)
xout <- as.numeric(xout)
} else {
index(object.x) <- x
}
objectm <- merge(object.x, zoo(, xout))
if (length(dim(objectm)) == 2) colnames(objectm) <- colnames(object)
result <- window(objectm, index = xout)
}
result[] <- na.spline.default(object, x = x, xout = xout, na.rm = FALSE, ..., maxgap = maxgap)
if ((!missing(order.by) && !is.null(order.by)) || !missing.xout) {
index(result) <- order.by
}
if (na.rm) {
result <- na.trim(result, is.na = "all", maxgap = maxgap)
}
result
}na.spline — one of the package’s own names, itself untypedname: na.spline
na.spline.zooreg <- function(object, ...) {
object. <- structure(object, class = setdiff(class(object), "zooreg"))
as.zooreg(na.spline(object., ...))
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
na.spline.ts <- function(object, ...) {
as.ts(na.spline(as.zoo(object), ...))
}unnamed — a name the prelude does not declarename: unnamed
make.par.list <- function(nams, x, n, m, def, recycle = sum(unnamed) > 0) {
##FIXME: should defaults for n, m, def be available?
# if nams are the names of our variables and x is a parameter
# specification such as list(a = c(1,2), c(3,4)) then
# create a new list which uses the named variables from x
# and assigns the unnamed in order. For the remaining variables
# assign them the default value if recycle = FALSE or recycle the
# unnamed variables if recycle = TRUE. The default value for
# recycle is TRUE if there is at least one unnamed variable
# in x and is false if there are only named variables in x.
# n is the length of the series and m is the total number of series
# It only needs to know whether m is 1 or greater than m.
# def is the default value used when recycle = FALSE
# recycle = TRUE means recycle unspecified values
# recycle = FALSE means replace values for unspecified series with def
# Within series recycling is done even if recycle=FALSE.
# Should we allow arbirary names in 1d case?
# if (m > 1) stopifnot(all(names(x) %in% c("", nams)))
if (!is.list(x)) x <- if (m == 1) list(x) else as.list(x)
y <- vector(mode = "list", length = length(nams))
names(y) <- nams
in.x <- nams %in% names(x)
unnamed <- if (is.null(names(x))) rep(TRUE, length(x)) else names(x) == ""
if (!recycle) y[] <- def
y[in.x] <- x[nams[in.x]]
if (recycle) {
stopifnot(sum(unnamed) > 0)
y[!in.x] <- rep(x[unnamed], length.out = sum(!in.x)) ## CHECK, this was: x[unnamed]
} else {
y[which(!in.x)[seq_len(sum(unnamed))]] <- x[unnamed]
}
lapply(y, function(y) if (length(y)==1) y else rep(y, length.out = n))
}Invalid_argument("Variable ..._5 is already bound.")plot.zoo <- function(x, y = NULL, screens, plot.type, panel = lines,
xlab = "Index", ylab = NULL, main = NULL, xlim = NULL, ylim = NULL,
xy.labels = FALSE, xy.lines = NULL, yax.flip = FALSE,
oma = c(6, 0, 5, 0), mar = c(0, 5.1, 0, if(yax.flip) 5.1 else 2.1),
col = 1, lty = 1, lwd = 1, pch = 1, type = "l", log = "",
nc, widths = 1, heights = 1, ...)
{
## if y supplied: scatter plot y ~ x
if(!is.null(y)) {
if(NCOL(x) > 1 || NCOL(y) > 1) stop("scatter plots only for univariate zoo series")
xyzoo <- merge.zoo(x, y, all = FALSE)
xy <- coredata(xyzoo)
xy <- xy.coords(xy[,1], xy[,2])
xlab <- if(missing(xlab)) deparse(substitute(x)) else xlab
ylab <- if(missing(ylab)) deparse(substitute(y)) else ylab
xlim <- if(is.null(xlim)) range(xy$x[is.finite(xy$x)]) else xlim
ylim <- if(is.null(ylim)) range(xy$y[is.finite(xy$y)]) else ylim
if(is.null(main)) main <- ""
do.lab <- if(is.logical(xy.labels)) xy.labels else TRUE
if(is.null(xy.lines)) xy.lines <- do.lab
ptype <- if(do.lab) "n" else if(missing(type)) "p" else type
plot.default(xy, type = ptype,col = col, pch = pch, main = main,
xlab = xlab, ylab = ylab, xlim = xlim, ylim = ylim, log = log, ...)
if(do.lab) text(xy, col = col,
labels = if(!is.logical(xy.labels)) xy.labels else index2char(index(xyzoo)), ...)
if(xy.lines) lines(xy, col = col, lty = lty, lwd = lwd, type = if(do.lab) "c" else "l", ...)
return(invisible(xyzoo))
}
## Else : no y, only x
recycle <- function(a, len, nser)
rep(lapply(as.list(a), rep, length.out = len), length.out = nser)
# same as range except it passes pairs through
range2 <- function(x, ...) if (length(x) == 2) x else range(x, ...)
if (missing(plot.type)) {
plot.type <- if (missing(screens)) "multiple"
else if (length(unique(screens) == 1)) "single"
else "multiple"
}
plot.type <- match.arg(plot.type, c("multiple", "single"))
nser <- NCOL(x)
if (missing(screens)) {
screens <- if (plot.type == "single") 1 else seq_len(nser)
}
dots <- list(...)
x.index <- index(x)
if(is.ts(x.index)) x.index <- as.vector(x.index)
cn <- if (is.null(colnames(x))) paste("V", seq_len(nser), sep = "")
else colnames(x)
screens <- make.par.list(cn, screens, NROW(x), nser, 1)
screens <- as.factor(unlist(screens))[drop = TRUE]
ngraph <- length(levels(screens))
if(nser > 1 && (plot.type == "multiple" || ngraph > 1)) {
if (ngraph == 1) {
screens <- as.factor(seq(nser))
ngraph <- nser
}
if(is.null(main)) main <- deparse(substitute(x))
main.outer <- TRUE
if(is.null(ylab)) ylab <- colnames(x)[!duplicated(screens)]
if(is.null(ylab)) ylab <- paste("Series", which(!duplicated(screens)))
if(is.call(ylab)) ylab <- as.expression(ylab)
ylab <- rep(ylab, length.out = ngraph)
if(!is.list(ylab)) ylab <- as.list(ylab)
lty <- rep(lty, length.out = nser)
lwd <- rep(lwd, length.out = nser)
col <- make.par.list(cn, col, NROW(x), nser, 1)
pch <- make.par.list(cn, pch, NROW(x), nser, par("pch"))
type <- make.par.list(cn, type, NROW(x), nser, "l")
if (!is.null(ylim)) {
if (is.list(ylim)) ylim <- lapply(ylim, range2, na.rm = TRUE)
else ylim <- list(range2(ylim, na.rm = TRUE))
ylim <- lapply(make.par.list(cn, ylim, 2, nser, NULL), function(x)
if (is.null(x) || length(na.omit(x)) == 0) NULL
else range2(x, na.rm = TRUE))
}
panel <- match.fun(panel)
if(missing(nc)) nc <- if(ngraph > 4) 2 else 1
oldpar <- par(no.readonly = TRUE)
on.exit({ par(oldpar) })
nr <- ceiling(ngraph / nc)
layout(matrix(seq(nr*nc), nr), widths = widths, heights = heights)
par(mar = mar, oma = oma)
# TRUE if all elements of L are the same -- else FALSE
allsame <- function(L) {
f <- function(x, y) if (identical(x, y)) x
!is.null(Reduce(f, L))
}
# idx is vector of indices into ylim.
# If the entries indexed by it are all the same then use that common value;
# otherwise, if the ylim are specified use the range of the ylim values;
# otherwise, use the range of the data
f <- function(idx) if (allsame(ylim)) ylim[idx][[1]]
else if (!is.null(ylim) && length(idx) > 0 &&
length(unlist(ylim[idx])) > 0) range(ylim[idx], finite = TRUE)
else range(x[, idx], na.rm = TRUE)
# ranges is indexed by screen
ranges <- tapply(1:ncol(x), screens, f)
for(j in seq_along(levels(screens))) {
panel.number <- j
y.side <- if (j %% 2 || !yax.flip) 2 else 4
range. <- rep(ranges[[j]], length.out = length(time(x)))
if(j%%nr==0 || j == length(levels(screens))) {
args <- list(x.index, range., xlab = "", ylab = "", yaxt = "n",
xlim = xlim, ylim = ylim[[j]], log = log, ...)
args$type <- "n"
do.call("plot", args)
mtext(xlab, side = 1, line = 3)
} else {
args <- list(x.index, range., xaxt = "n", yaxt = "n", xlab = "",
ylab = "", xlim = xlim, ylim = ylim[[j]], log = log, ...)
args$type <- "n"
do.call("plot", args)
if ("bty" %in% names(args) && args$bty == "n") {} else box()
}
do.call("axis", c(list(side = y.side, xpd = NA), dots))
mtext(ylab[[j]], y.side, line = 3)
for(i in which(screens == levels(screens)[j])) {
## for potential usage in panel function
series.number <- i
series.within.screen <- ave(seq_along(screens), screens, FUN = seq_along)[series.number]
## draw individual lines/points with panel function
panel(x.index, x[, i], col = col[[i]], pch = pch[[i]], lty = lty[i], lwd = lwd[i], type = type[[i]], ...)
}
}
} else {
if(is.null(ylab)) ylab <- deparse(substitute(x))
if(is.call(ylab)) ylab <- as.expression(ylab)
if(is.null(main)) main <- ""
main.outer <- FALSE
if(is.null(ylim)) ylim <- range(x, na.rm = TRUE)
else ylim <- range2(c(ylim, recursive = TRUE), na.rm = TRUE)
lty <- rep(lty, length.out = nser)
lwd <- rep(lwd, length.out = nser)
col <- make.par.list(cn, col, NROW(x), nser, 1)
pch <- make.par.list(cn, pch, NROW(x), nser, par("pch"))
type <- make.par.list(cn, type, NROW(x), nser, "l")
dummy <- rep(range(x, na.rm = TRUE),
length.out = length(index(x)))
args <- list(x.index, dummy, xlab = xlab, ylab = ylab[1], ylim = ylim, xlim = xlim, log = log, ...)
args$type <- "n"
do.call("plot", args)
if ("bty" %in% names(args) && args$bty == "n") {} else box()
y <- as.matrix(x)
for(i in 1:nser) {
panel(x.index, y[, i], col = col[[i]], pch = pch[[i]], lty = lty[i],
lwd = lwd[i], type = type[[i]], ...)
}
}
dots <- list(...)
title.args <- c(list(main = main, outer = main.outer),
dots[grep("[.]main$", names(dots))])
do.call("title", title.args)
return(invisible(x))
}NCOL — a name the prelude does not declarename: NCOL
lines.zoo <- function(x, y = NULL, type = "l", ...)
{
if (is.null(y)) {
if(NCOL(x) == 1) lines(index(x), x, type = type, ...)
else stop("Can't plot lines for multivariate zoo object")
} else
lines(coredata(cbind(x,y)), type = type, ...)
}lines — a name the prelude does not declarename: lines
points.zoo <- function(x, y = NULL, type = "p", ...)
lines(x, y, type = type, ...)as.zoo — one of the package’s own names, itself untypedname: as.zoo
plot.tis <- function(x, ...) eval.parent(substitute(plot(as.zoo(x), ...)))tis::POSIXct — a name the prelude does not declarename: tis::POSIXct
plot.ti <- function (x, y, xlab = "", ...)
{
x <- tis::POSIXct(x)
NextMethod()
}tis::POSIXct — a name the prelude does not declarename: tis::POSIXct
points.ti <- lines.ti <- function(x, ...) {
x <- tis::POSIXct(x)
NextMethod()
}read.zoo <- function(file, format = "", tz = "", FUN = NULL,
regular = FALSE, index.column = 1, drop = TRUE, FUN2 = NULL,
split = NULL, aggregate = FALSE, ..., text, read = read.table)
{
if (missing(file) && !missing(text)) {
file <- textConnection(text)
on.exit(close(file))
}
## if file is a vector of file names
if (is.character(file) && length(file) > 1) {
mc <- match.call()
pf <- parent.frame()
L <- sapply(file, function(file) eval(replace(mc, 2, file), pf),
simplify = FALSE)
return(do.call("merge", L))
}
## read data
rval <- if (is.data.frame(file)) {
if(inherits(file, "tbl")) as.data.frame(file) else file
} else {
read(file, ...)
}
## if time index appears to be already processed, use FUN = identity
if (is.data.frame(file) &&
!identical(index.column, 0) &&
!identical(index.column, 0L) &&
length(index.column) == 1 &&
!is.character(rval[[index.column]]) &&
!is.factor(rval[[index.column]]) &&
missing(tz) &&
missing(format) &&
missing(FUN)) FUN <- identity
## if time index is POSIXlt it is coerced to POSIXct
if (is.data.frame(file) &&
!identical(index.column, 0) &&
!identical(index.column, 0L) &&
length(index.column) == 1 &&
inherits(rval[[index.column]], "POSIXlt")) rval[[index.column]] <- as.POSIXct(rval[[index.column]])
# returns TRUE if a formal argument x has no default
no.default <- function(x) typeof(x) %in% c("symbol", "language")
if (is.null(FUN) && is.null(FUN2)) {
index.column <- as.list(index.column)
} else if (identical(FUN, paste)) {
index.column <- as.list(index.column)
} else if (is.null(FUN) && identical(FUN2, paste)) {
index.column <- as.list(index.column)
} else if (!is.null(FUN) && !is.list(index.column) && length(index.column) <=
length(sapply(formals(match.fun(FUN)), no.default))) {
index.column <- as.list(index.column)
} else if (is.null(FUN) && !is.null(FUN2) && length(index.column) <=
length(sapply(formals(match.fun(FUN2)), no.default))) {
index.column <- as.list(index.column)
}
if (is.list(index.column) && length(index.column) == 1 &&
index.column[[1]] == 1) index.column <- unlist(index.column)
is.index.column <- unname(unlist(index.column))
is.index.column <- if(is.numeric(is.index.column)) {
seq_along(rval) %in% is.index.column
} else {
seq_along(rval) %in% is.index.column | names(rval) %in% is.index.column
}
name.to.num <- function(x) if (is.character(x))
match(x, names(rval), nomatch = 0) else x
index.column <- if (is.list(index.column)) index.column <-
lapply(index.column, name.to.num)
else name.to.num(index.column)
## convert factor columns in index to character
is.fac <- sapply(rval, is.factor)
is.fac.index <- is.fac & is.index.column
if (any(is.fac.index)) rval[is.fac.index] <-
lapply(rval[is.fac.index], as.character)
## if file does not contain index or data
if(NROW(rval) < 1) {
if(is.data.frame(rval)) rval <- as.matrix(rval)
if(NCOL(rval) > 1) rval <- rval[, ! is.index.column, drop = drop]
rval2 <- zoo(rval)
return(rval2)
}
## extract index
if(NCOL(rval) < 1) stop("data file must specify at least one column")
## extract index, retain rest of the data
ix <- if (identical(index.column, 0) || identical(index.column, list(0)) ||
identical(index.column, 0L) || identical(index.column, list(0L))) {
attributes(rval)$row.names
} else if (is.list(index.column)) {
sapply(index.column, function(j) rval[,j], simplify = FALSE)
} else rval[,index.column]
# split. is col number of split column (or Inf, -Inf or NULL)
split. <- if (is.character(split)) match(split, colnames(rval), nomatch = 0)
else split
rval2 <- if (is.null(split.)) {
rval[ , ! is.index.column, drop = FALSE]
} else {
split.values <- if (is.character(split) || all(is.finite(split))) rval[, split]
else {
# Inf: first value in each run is first series, etc.
# -Inf: last value in each run is first series, etc.
if (identical(split, Inf)) ave(ix, ix, FUN = seq_along)
else if (identical(split, -Inf)) ave(ix, ix, FUN = function(x) rev(seq_along(x)))
else ix
}
if (0 %in% split.) {
stop(paste("split:", split, "not found in colnames:", colnames(rval)))
}
rval[,-c(if (all(is.finite(split.))) split. else 0, which(is.index.column)), drop = FALSE]
}
if(is.factor(ix)) ix <- as.character(ix)
rval3 <- if(is.data.frame(rval2)) as.matrix(rval2) else if(is.list(rval2)) t(rval2) else rval2
if(NCOL(rval3) == 1 && drop) rval3 <- drop(rval3)
## index transformation functions
toDate <- if(missing(format) || is.null(format)) {
function(x, ...) as.Date(format(x, scientific = FALSE))
} else {
function(x, format) {
if(any(sapply(c("%H", "%M", "%S"), function(y) grepl(y, format, fixed = TRUE)))) {
warning("the 'format' appears to be for a date/time, please specify 'tz' if you want to create a POSIXct time index")
}
as.Date(format(x, scientific = FALSE), format = format)
}
}
toPOSIXct <- if (missing(format) || is.null(format)) {
function(x, tz) as.POSIXct(format(x, scientific = FALSE), tz = tz)
} else function(x, format, tz) {
as.POSIXct(strptime(format(x, scientific = FALSE), tz = tz, format = format))
}
toDefault <- function(x, ...) {
rval. <- try(toPOSIXct(x, tz = ""), silent = TRUE)
if(inherits(rval., "try-error"))
rval. <- try(toDate(x), silent = TRUE)
else {
hms <- as.POSIXlt(rval.)
hms <- hms$sec + 60 * hms$min + 3600 * hms$hour
if(isTRUE(all.equal(hms, rep.int(hms[1], length(hms))))) {
rval2. <- try(toDate(x), silent = TRUE)
if(!inherits(rval2., "try-error")) rval. <- rval2.
}
}
if(inherits(rval., "try-error")) rval. <- rep(NA, length(x))
return(rval.)
}
toNumeric <- function(x, ...) x
## setup default FUN
if ((missing(FUN) || is.null(FUN)) && !missing(FUN2) && !is.null(FUN2)) {
FUN <- FUN2
FUN2 <- NULL
}
FUN0 <- NULL
if(is.null(FUN)) {
if (is.list(index.column)) FUN0 <- paste
FUN <- if (!missing(tz) && !is.null(tz)) toPOSIXct
else if (!missing(format) && !is.null(format)) toDate
else if (is.numeric(ix)) toNumeric
else toDefault
}
FUN <- match.fun(FUN)
processFUN <- function(...) {
if (is.data.frame(..1)) FUN(...)
else if (is.list(..1)) {
if (is.null(FUN0)) do.call(FUN, c(...))
else {
L <- list(...)
L[[1]] <- do.call(FUN0, L[[1]])
do.call(FUN, L)
}
} else FUN(...)
}
## compute index from (former) first column
ix <- if (missing(format) || is.null(format)) {
if (missing(tz) || is.null(tz)) processFUN(ix) else processFUN(ix, tz = tz)read.table — a name the prelude does not declarename: read.table
read.table.zoo <- function(file, format = "", tz = "", FUN = NULL,
regular = FALSE, index.column = 1, drop = TRUE, FUN2 = NULL,
split = NULL, aggregate = FALSE, ...)
{
file <- read.table(file, ...)
read.zoo(file, format = format, tz = tz, FUN = FUN, regular = regular,
index.column = index.column, drop = drop, FUN2 = FUN2,
split = split, aggregate = aggregate)
}Failure("Unsupported argument after an ellipsis.")read.csv.zoo <- function(..., read = read.csv) {
read.zoo(..., read = read)
}Failure("Unsupported argument after an ellipsis.")read.csv2.zoo <- function(..., read = read.csv2) {
read.zoo(..., read = read)
}Failure("Unsupported argument after an ellipsis.")read.delim.zoo <- function(..., read = read.delim) {
read.zoo(..., read = read)
}Failure("Unsupported argument after an ellipsis.")read.delim2.zoo <- function(..., read = read.delim2) {
read.zoo(..., read = read)
}colnames — a name the prelude does not declarename: colnames
write.zoo <- function(x, file = "", index.name = "Index",
row.names = FALSE, col.names = NULL, FUN = format, ...)
{
if(is.null(col.names)) col.names <- !is.null(colnames(x))
dx <- as.data.frame(x)
stopifnot(all(names(dx) != index.name))
dx[[index.name]] <- FUN(index(x))
dx <- dx[, c(ncol(dx), 1:(ncol(dx)-1))]
write.table(dx, file = file, row.names = row.names, col.names = col.names, ...)
}UseMethod — a name the prelude does not declarename: UseMethod
rollmean <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...) {
UseMethod("rollmean")
}Failure("Unsupported argument after an ellipsis.")rollmeanr <- function(..., align = "right") {
rollmean(..., align = align)
}Failure("Unsupported positional argument after a named one.")rollmean.zoo <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...) {
if (length(x) < 1L) return(x)
if (!missing(na.pad)) warning("na.pad is deprecated. Use fill.")
align <- match.arg(align)
n <- length(index(x))
k <- trunc(k)
if(k > n || anyNA(coredata(x))) return(rollapply(x, k, FUN = (mean), fill = fill, align = align, ...))
if (length(dim(x)) == 2) {
# merge is the only zoo specific part of this method
out <- do.call("merge", c(lapply(1:NCOL(x), function(i) {
rollmean(x[, i, drop = TRUE], k, fill = fill, align = align, ...)
}), all = FALSE))
if (ncol(x) == 1) dim(out) <- c(length(out), 1)
colnames(out) <- colnames(x)
return(out)
}
ix <- switch(align,
"left" = { 1:(n-k+1) },
"center" = { floor((1+k)/2):ceiling(n-k/2) },
"right" = { k:n })
xu <- unclass(x)
y <- xu[k:n] - xu[c(1, seq_len(n-k))] # difference from previous
y[1] <- sum(xu[1:k]) # find the first
# sum precomputed differences
rval <- cumsum(y)/k
x[ix] <- rval
na.fill(x, fill = fill, ix)
}zoo — one of the package’s own names, itself untypedname: zoo
rollmean.default <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
{
if (length(x) < 1L) return(x)
coredata(rollmean(zoo(x), k, fill = fill, align = align, ...))
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
rollmean.ts <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
{
if (length(x) < 1L) return(x)
as.ts(rollmean(as.zoo(x), k, fill = fill, align = align, ...))
}UseMethod — a name the prelude does not declarename: UseMethod
rollsum <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...) {
UseMethod("rollsum")
}Failure("Unsupported argument after an ellipsis.")rollsumr <- function(..., align = "right") {
rollsum(..., align = align)
}Failure("Unsupported positional argument after a named one.")rollsum.zoo <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
{
if (length(x) < 1L) return(x)
if (!missing(na.pad)) warning("na.pad is deprecated. Use fill.")
align <- match.arg(align)
n <- length(index(x))
k <- trunc(k)
if(k > n || anyNA(coredata(x))) return(rollapply(x, k, FUN = (sum), fill = fill, align = align, ...))
if (length(dim(x)) == 2) {
# merge is the only zoo specific part of this method
out <- do.call("merge", c(lapply(1:NCOL(x), function(i) {
rollsum(x[, i, drop = TRUE], k, fill = fill, align = align, ...)
}), all = FALSE))
if (ncol(x) == 1) dim(out) <- c(length(out), 1)
colnames(out) <- colnames(x)
return(out)
}
ix <- switch(align,
"left" = { 1:(n-k+1) },
"center" = { floor((1+k)/2):ceiling(n-k/2) },
"right" = { k:n })
xu <- unclass(x)
y <- xu[k:n] - xu[c(1, seq_len(n-k))] # difference from previous
y[1] <- sum(xu[1:k]) # find the first
# sum precomputed differences
rval <- cumsum(y)
x[ix] <- rval
na.fill(x, fill = fill, ix)
}zoo — one of the package’s own names, itself untypedname: zoo
rollsum.default <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
{
if (length(x) < 1L) return(x)
coredata(rollsum(zoo(x), k, fill = fill, align = align, ...))
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
rollsum.ts <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
{
if (length(x) < 1L) return(x)
as.ts(rollsum(as.zoo(x), k, fill = fill, align = align, ...))
}UseMethod — a name the prelude does not declarename: UseMethod
rollmax <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...) {
UseMethod("rollmax")
}Failure("Unsupported argument after an ellipsis.")rollmaxr <- function(..., align = "right") {
rollmax(..., align = align)
}Failure("Unsupported positional argument after a named one.")rollmax.zoo <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
{
if (length(x) < 1L) return(x)
if (!missing(na.pad)) warning("na.pad is deprecated. Use fill.")
align <- match.arg(align)
if (length(dim(x)) == 2) {
# merge is the only zoo specific part of this method
out <- do.call("merge", c(lapply(1:NCOL(x), function(i) {
rollmax(x[, i, drop = TRUE], k, fill = fill, align = align, ...)
}), all = FALSE))
if (ncol(x) == 1) dim(out) <- c(length(out), 1)
colnames(out) <- if (ncol(x) == ncol(out)) colnames(x)
return(out)
}
n <- length(x)
k <- trunc(k)
if(k > n) return(rollapply(x, k, FUN = (max), fill = fill, align = align, ...))
ix <- switch(align,
"left" = { 1:(n-k+1) },
"center" = { floor((1+k)/2):ceiling(n-k/2) },
"right" = { k:n })
n <- length(x)
rval <- rep(0, n)
a <- 0
xc <- coredata(x)
if(k == 1) {
rval <- xc
} else {
for (i in k:n) {
rval[i] <- if (is.na(a) || is.na(rval[i-1]) || a==rval[i-1])
max(xc[(i-k+1):i]) # calculate max of window
else
max(rval[i-1], xc[i]); # max of window = rval[i-1]
a <- xc[i-k+1] # point that will be removed from window
}
rval <- rval[-seq(k-1)]
}
x[ix] <- rval
na.fill(x, fill = fill, ix)
}zoo — one of the package’s own names, itself untypedname: zoo
rollmax.default <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
{
if (length(x) < 1L) return(x)
coredata(rollmax(zoo(x), k, fill = fill, align = align, ...))
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
rollmax.ts <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
{
if (length(x) < 1L) return(x)
as.ts(rollmax(as.zoo(x), k, fill = fill, align = align, ...))
}UseMethod — a name the prelude does not declarename: UseMethod
rollmedian <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...) {
UseMethod("rollmedian")
}Failure("Unsupported argument after an ellipsis.")rollmedianr <- function(..., align = "right") {
rollmedian (..., align = align)
}Failure("Unsupported positional argument after a named one.")rollmedian.zoo <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
{
if (length(x) < 1L) return(x)
if (!missing(na.pad)) warning("na.pad is deprecated. Use fill.")
align <- match.arg(align)
n <- length(index(x))
k <- trunc(k)
if(k > n || anyNA(coredata(x))) return(rollapply(x, k, FUN = (median), fill = fill, align = align, ...))
if (length(dim(x)) == 2) {
# merge is the only zoo specific part of this method
out <- do.call("merge", c(lapply(1:NCOL(x), function(i) {
rollmedian(x[, i, drop = TRUE], k, fill = fill, align = align, ...)
}), all = FALSE))
if (ncol(x) == 1) dim(out) <- c(length(out), 1)
colnames(out) <- colnames(x)
return(out)
}
ix <- switch(align,
"left" = { 1:(n-k+1) },
"center" = { floor((1+k)/2):ceiling(n-k/2) },
"right" = { k:n })
m <- k %/% 2
rval <- runmed(x, k, ...)
attr(rval, "k") <- NULL
if(m >= 1) rval <- rval[-c(1:m, (n-m+1):n)]
x[ix] <- rval
na.fill(x, fill = fill, ix)
}zoo — one of the package’s own names, itself untypedname: zoo
rollmedian.default <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
{
if (length(x) < 1L) return(x)
coredata(rollmedian(zoo(x), k, fill = fill, align = align, ...))
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
rollmedian.ts <- function(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
{
if (length(x) < 1L) return(x)
as.ts(rollmedian(as.zoo(x), k, fill = fill, align = align, ...))
}UseMethod — a name the prelude does not declarename: UseMethod
rollapply <- function(data, ...) UseMethod("rollapply")Failure("Unsupported argument after an ellipsis.")rollapplyr <- function(..., align = "right") {
rollapply(..., align = align)
}zoo — one of the package’s own names, itself untypedname: zoo
rollapply.default <- function(data, ...) {
if (length(data) < 1L) return(data)
coredata(rollapply(zoo(data), ...))
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
rollapply.ts <- function(data, ...) {
if (length(data) < 1L) return(data)
as.ts(rollapply(as.zoo(data), ...))
}Failure("Unsupported argument after an ellipsis.")rollapply.zoo <- function(data, width, FUN, ..., by = 1,
by.column = TRUE, fill = if (na.pad) NA, na.pad = FALSE,
partial = FALSE, align = c("center", "left", "right"), coredata = TRUE) {
if (length(data) < 1L) return(data)
if (!missing(na.pad)) {
warning("na.pad argument is deprecated")
}
if (is.vector(width) && !is.list(width) && length(width) == 1 &&
by.column && length(by) == 1 && by == 1 && (missing(partial) | identical(partial, FALSE)) &&
length(list(...)) < 1 && length(sw <- deparse(substitute(FUN))) == 1) {
if (sw == "mean" && !anyNA(data)) {
return(rollmean(data, width, fill = fill, align = align))
} else if (sw == "median" && width %% 2 == 1 && !anyNA(data)) {
return(rollmedian(data, width, fill = fill, align = align))
} else if (sw == "max") {
return(rollmax(data, width, fill = fill, align = align))
}
}
FUN <- match.fun(FUN)
if (by.column && length(dim(data)) == 2) {
z <- do.call(merge,
lapply(1:NCOL(data), function(j)
rollapply(data[, j, drop = TRUE], width = width, FUN = FUN, ...,
by = by, by.column = by.column, fill = fill,
partial = partial, align = align, coredata = coredata)
)
)
if (NCOL(data) == 1) dim(z) <- c(length(z), 1)
colnames(z) <- if (NCOL(z) == NCOL(data)) colnames(data)
return(z)
}
if (is.logical(partial)) partial <- if (partial) 1 else -1
# convert widths to offsets using align
align <- match.arg(align)
width <- if (!is.list(width)) {
lapply(trunc(width), function(w) {
if (align == "right") seq(to = 0, length.out = w)
else if (align == "center") seq(to = floor(w/2), length.out = w)
else seq(from = 0, length.out = w)
})
} else {
lapply(width, function(w) {
if(is.null(w)) NULL else trunc(w)
})
}
# recycle width (using by if length(width) == 1)
width <- if (length(width) == 1) {
w <- rep(list(NULL), NROW(data))
start.at <- if (partial < 0) max(-min(width[[1]]), 0) + 1 else 1
start.at <- min(NROW(data), start.at)
replace(w, seq(start.at, NROW(data), by = by), width)
} else rep(width, length.out = NROW(data))
f <- if (is.null(dim(data))) {
# undimensioned
#
# if FUN is to be evaluated at offsets for the ith point then calculate
# positions, do partial processing and apply FUN
function(i, offsets, data, ...) {
if (is.null(offsets)) return(NULL)
posns <- i + offsets
ix <- posns >= 1 & posns <= NROW(data)
if (partial < 0) {
if (all(ix)) FUN(data[posns], ...)
} else if (sum(ix) >= partial) {
FUN(data[replace(posns, !ix, 0)], ...)
}
}
} else {
# dimensioned
#
# same f as in TRUE leg except data[.] becomes data[.,]
function(i, offsets, data, ...) {
if (is.null(offsets)) return(NULL)
posns <- i + offsets
ix <- posns >= 1 & posns <= NROW(data)
if (partial < 0) {
if (all(ix)) FUN(data[posns,], ...)
} else if (sum(ix) >= partial) {
FUN(data[replace(posns, !ix, 0),], ...)
}
}
}
dat <- if(coredata) coredata(data) else data
dat <- mapply(f, seq_along(time(data)), width,
MoreArgs = list(data = dat, ...), SIMPLIFY = FALSE)
ix <- !sapply(dat, is.null) # integer indexes of non-nulls
## flatten data if output of FUN has a dim and > 1 row (e.g., matrix or data.frame)
if(any(sapply(dat[ix], function(d) !is.null(nrow(d)) && nrow(d) > 1L))) {
dat[ix] <- lapply(dat[ix], function(d) unlist(as.data.frame(d)))
}
if (!missing(fill) || !missing(na.pad)) {
# replace NULLs with NAs
dat <- lapply(dat, function(x) if (is.null(x)) NA else x)
# construct zoo object
dat <-
if (max(sapply(dat, length)) > 1)
zoo(do.call("rbind", dat), index(data), attr(data, "frequency"))
else
zoo(do.call("c", dat), index(data), attr(data, "frequency"))
# perform filling
dat <- na.fill(dat, fill, ix)
} else {
# construct zoo object removing points corresponding to NULL
dat <- if (max(sapply(dat, length)) > 1)
zoo(do.call("rbind", dat), index(data)[ix], attr(data, "frequency"))
else
zoo(do.call("c", dat), index(data)[ix], attr(data, "frequency"))
}
dat
}substitute — a name the prelude does not declarename: substitute
tinyplot.zoo <- function(object, facet, type = "l", facet.args = list(free = TRUE), ylab = "", ...)
{
## convert to data.frame (and assure correct label processing by fortify.zoo)
lab <- deparse(substitute(object))
if(NCOL(object) == 1L) {
if(is.null(dim(object))) dim(object) <- c(NROW(object), 1L)
if(is.null(colnames(object))) colnames(object) <- lab
}
if(is.null(colnames(object))) colnames(object) <- paste(lab, 1:NCOL(object), sep = ".")
df <- fortify.zoo(object, melt = TRUE)
## default for facet
single <- nlevels(df$Series) == 1L
if(missing(facet)) {
auto <- TRUE
facet <- if(single) NULL else ~ Series
} else {
auto <- FALSE
}
if (is.null(facet)) facet.args <- NULL
## call tinyplot
if(single | (!is.null(facet) & auto)) {
tinyplot::tinyplot(Value ~ Index, data = df, facet = facet, facet.args = facet.args, type = type, ylab = ylab, ...)
} else {
tinyplot::tinyplot(Value ~ Index | Series, data = df, facet = facet, facet.args = facet.args, type = type, ylab = ylab, ...)
}
}index — one of the package’s own names, itself untypedname: index
window.zoo <- function(x, index. = index(x), start = NULL, end = NULL, ...)
{
all.indexes <- index(x)
in.index <- MATCH(all.indexes, index., nomatch = 0) > 0
if(length(start) == 2 && !is.null(attr(x, "frequency")) && is.numeric(all.indexes)) {
freq <- attr(x, "frequency")
start <- floor(start[1]*freq + (start[2] - 1) + .0001)/freq
}
if(length(end) == 2 && !is.null(attr(x, "frequency")) && is.numeric(all.indexes)) {
freq <- attr(x, "frequency")
end <- floor(end[1]*freq + (end[2] - 1) + .0001)/freq
}
if(is.null(start) || any(is.na(start))) {
if(is.null(end) || any(is.na(end))) {
wi <- which(MATCH(all.indexes, index., nomatch = 0) > 0)
return(x[wi, , drop = FALSE])
} else {
wi <- which(in.index & all.indexes <= end)
return(x[wi, , drop = FALSE])
}
} else {
if(is.null(end) || any(is.na(end))) {
wi <- which(in.index & all.indexes >= start)
} else {
wi <- which(in.index & all.indexes >= start & all.indexes <= end)
}
return(x[wi, , drop = FALSE])
}
}index — one of the package’s own names, itself untypedname: index
"window<-.zoo" <- function(x, index. = index(x), start = NULL, end = NULL, ..., value)
{
ix <- index(x)
stopifnot(all(MATCH(index., ix, nomatch = 0) > 0))
if(length(start) == 2 && !is.null(attr(x, "frequency")) && is.numeric(ix)) {
freq <- attr(x, "frequency")
start <- floor(start[1]*freq + (start[2] - 1) + .0001)/freq
}
if(length(end) == 2 && !is.null(attr(x, "frequency")) && is.numeric(ix)) {
freq <- attr(x, "frequency")
end <- floor(end[1]*freq + (end[2] - 1) + .0001)/freq
}
if (!is.null(start) && !is.na(start)) index. <- index.[index. >= start]
if (!is.null(end) && !is.na(end)) index. <- index.[index. <= end]
wi <- which(MATCH(ix, index., nomatch = 0) > 0)
if (length(dim(x)) == 0)
x[wi] <- value
else
x[wi,] <- value
return(x)
}lag.zoo — one of the package’s own names, itself untypedname: lag.zoo
lag.zoo <- function(x, k = 1, na.pad = FALSE, ...)
{
if (length(k) > 1) {
if (is.null(names(k))) names(k) <- paste("lag", k, sep = "")
return(do.call("merge.zoo", lapply(k, lag.zoo, x = x, na.pad = na.pad, ...)))
}
nr <- NROW(x)
if (k != round(k)) {
k <- round(k)
warning("k is not an integer")
}
if (k == 0) return(x)
if (abs(k) > nr) k <- nr
if (k > 0) {
xx <- x[-seq(1, length.out = k),, drop = FALSE]
attr(xx, "index") <- index(x)[-seq(to = nr, length.out = k)]
} else {
xx <- x[-seq(to = nr, length.out = -k),, drop = FALSE]
attr(xx, "index") <- index(x)[-seq(1, length.out = -k)]
}
if (na.pad) merge(zoo(,time(x)), xx, all = c(TRUE, FALSE)) else xx
}lag.zooreg — one of the package’s own names, itself untypedname: lag.zooreg
lag.zooreg <- function(x, k = 1, na.pad = FALSE, ...)
{
if (length(k) > 1) {
if (is.null(names(k))) names(k) <- paste("lag", k, sep = "")
return(do.call("merge.zoo", lapply(k, lag.zooreg, x = x, na.pad = na.pad, ...)))
}
x0 <- x
nr <- NROW(x)
freq <- attr(x, "frequency")
if (k != round(k)) warning("k is not an integer")
k <- round(k)
ix <- index(x)
ix <- if(identical(class(ix), "numeric") | identical(class(ix), "integer"))
floor(freq*ix - k + .0001)/freq else ix - k/freq
index(x) <- ix
if (na.pad) merge(x, zoo(, time(x0))) else x
}index — one of the package’s own names, itself untypedname: index
diff.zoo <- function(x, lag = 1, differences = 1, arithmetic = TRUE, na.pad = FALSE, log = FALSE, ...)
{
ix <- index(x)
stopifnot(differences >= 1)
## for relative differences, use division only if 'x' contains negative values
## other numerically more stable log-transform
if(arithmetic || all(coredata(x) > 0)) {
if (!arithmetic || log) x <- log(x)
if (lag > 0) for(i in 1:differences) x <- x - lag(x, k = -lag, ...) else for(i in 1:differences) x <- lag(x, k = -lag, ...) - x
if (!arithmetic) x <- exp(x)
} else {
if (lag > 0) for(i in 1:differences) x <- x / lag(x, k = -lag, ...) else for(i in 1:differences) x <- lag(x, k = -lag, ...) / x
}
if (na.pad) merge(zoo(,ix), x, all = c(TRUE, FALSE)) else x
}UseMethod — a name the prelude does not declarename: UseMethod
xblocks <- function(x, ...)
UseMethod("xblocks")File "Rsem/lang/PAst.ml", line 210, characters 14-20: Assertion failed
xblocks.default <-
function (x, y, ..., col = NULL, border = NA,
ybottom = par("usr")[3], ytop = ybottom + height,
height = diff(par("usr")[3:4]),
last.step = median(diff(tail(x))))
{
if (is.function(y))
y <- y(x)
x <- as.numeric(x)
if (length(x) == 0) return()
if (is.unsorted(x, na.rm = TRUE))
stop("'x' should be ordered (increasing)")
if (is.na(last.step))
last.step <- 0
## Three cases:
## (1) If y is character, assume it gives the block colours
## -- unless 'col' is given, which over-rides it.
## (2) If y is logical, show blocks of TRUE values.
## (3) If y is numeric, show blocks of non-NA values.
if (is.logical(y)) {
y <- y
} else if (is.numeric(y)) {
y <- !is.na(y)
} else {
## this will convert factor, Date, etc to character:
y <- as.character(y)
}
## Note: rle treats each NA as unique (does not combine runs of NAs)
## so we need to replace NAs with a temporary value.
NAval <-
if (is.character(y)) "" else FALSE
y[is.na(y)] <- NAval
## find blocks (runs of constant values)
yrle <- rle(y)
## substitute NA values back in
blockCol <- yrle$values
blockCol[blockCol == NAval] <- NA
## for logical series, col default comes from palette()
if (is.logical(y) && is.null(col))
col <- palette()[1]
## set block colours if 'col' given
if (length(col) > 0) {
if (is.character(col))
col[col == ""] <- NA
ok <- !is.na(blockCol)
blockCol[ok] <- rep(col, length.out = sum(ok)) ## rep to avoid warnings
}
## work out block geometry
idxBounds <- cumsum(c(1, yrle$lengths))
idxStart <- head(idxBounds, -1)
idxEnd <- tail(idxBounds, -1)
idxEnd[length(idxEnd)] <- length(y)
blockStart <- x[idxStart]
blockEnd <- x[idxEnd]
blockEnd[length(blockEnd)] <- tail(blockEnd, 1) + last.step
blockWidth <- blockEnd - blockStart
## adjust for log scales
if (par("ylog")) {
ybottom <- 10^ybottom
ytop <- 10^ytop
}
## draw it
rect(xleft = blockStart, xright = blockEnd,
ybottom = ybottom, ytop = ytop,
col = blockCol, border = border, ...)
}index — one of the package’s own names, itself untypedname: index
xblocks.zoo <-
xblocks.ts <-
function(x, y = x, ...)
{
if (!is.function(y))
y <- coredata(y)
xblocks(index(x), y, ...)
}Failure("Unsupported argument after an ellipsis.")panel.plot.default <- function(x, y, subscripts, groups, panel = panel.xyplot,
col = 1, type = "p", pch = 20, lty = 1, lwd = 1, ...)
{
col <- rep(as.list(col), length.out = nlevels(groups))
type <- rep(as.list(type), length.out = nlevels(groups))
pch <- rep(as.list(pch), length.out = nlevels(groups))
lty <- rep(as.list(lty), length.out = nlevels(groups))
lwd <- rep(as.list(lwd), length.out = nlevels(groups))
for(g in 1:nlevels(groups)) {
idx <- g == unclass(groups[subscripts])
if (any(idx)) panel(x[idx], y[idx], ...,
col = col[[g]], type = type[[g]], pch = pch[[g]],
lty = lty[[g]], lwd = lwd[[g]])
}
.Deprecated(msg="panel.plot.default is no longer needed, just use panel.xyplot etc")
}Invalid_argument("Variable ..._5 is already bound.")panel.plot.custom <- function(...) {
args <- list(...)
function(...) {
dots <- list(...)
do.call("panel.plot.default", modifyList(dots, args))
}
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
xyplot.its <-
xyplot.ts <-
xyplot.zoo <- function(x, data, ...)
{
obj <- lattice::xyplot.ts(as.zoo(x), ...)
obj$call <- match.call()
obj
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
xyplot.tis <- function(x, data, ...)
{
x <- aggregate(as.zoo(x), tis::POSIXct, identity)
obj <- lattice::xyplot.ts(x, ...)
obj$call <- match.call()
obj
}time — a name the prelude does not declarename: time
llines.its <-
llines.tis <-
llines.zoo <- function(x, y = NULL, ...)
{
if (!is.null(y)) {
llines(coredata(x), y = y, ...)
} else {
llines(coredata(time(x)), y = coredata(x), ...)
}
}time — a name the prelude does not declarename: time
lpoints.its <-
lpoints.tis <-
lpoints.zoo <- function(x, y = NULL, ...)
{
if (!is.null(y)) {
lpoints(coredata(x), y = y, ...)
} else {
lpoints(coredata(time(x)), y = coredata(x), ...)
}
}time — a name the prelude does not declarename: time
ltext.its <-
ltext.tis <-
ltext.zoo <- function(x, y = NULL, ...)
{
if (!is.null(y)) {
ltext(coredata(x), y = y, ...)
} else {
ltext(coredata(time(x)), y = coredata(x), ...)
}
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
panel.lines.ts <-
panel.lines.its <-
panel.lines.tis <-
panel.lines.zoo <- function(x, ...) {
x <- as.zoo(x)
panel.lines(time(x), coredata(x), ...)
.Deprecated("panel.lines")
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
panel.points.ts <-
panel.points.its <-
panel.points.tis <-
panel.points.zoo <- function(x, ...) {
x <- as.zoo(x)
panel.points(time(x), coredata(x), ...)
.Deprecated("panel.points")
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
panel.text.ts <-
panel.text.its <-
panel.text.tis <-
panel.text.zoo <- function(x, ...) {
x <- as.zoo(x)
panel.text(time(x), coredata(x), ...)
.Deprecated("panel.text")
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
panel.segments.ts <-
panel.segments.its <-
panel.segments.tis <-
panel.segments.zoo <- function(x0, x1, ...) {
x0 <- as.zoo(x0)
x1 <- as.zoo(x1)
panel.segments(time(x0), coredata(x0), time(x1), coredata(x1), ...)
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
panel.rect.ts <-
panel.rect.its <-
panel.rect.tis <-
panel.rect.zoo <- function(x0, x1, ...) {
x0 <- as.zoo(x0)
x1 <- as.zoo(x1)
panel.rect(time(x0), coredata(x0), time(x1), coredata(x1), ...)
}as.zoo — one of the package’s own names, itself untypedname: as.zoo
panel.polygon.ts <-
panel.polygon.its <-
panel.polygon.tis <-
panel.polygon.zoo <- function(x, ...) {
x <- as.zoo(x)
panel.polygon(time(x), coredata(x), ...)
}variable: fun expected: null given: any expression may be: new.env()
register_s3_method <- function(pkg, generic, class, fun = NULL) {
stopifnot(is.character(pkg), length(pkg) == 1L)
stopifnot(is.character(generic), length(generic) == 1L)
stopifnot(is.character(class), length(class) == 1L)
if (is.null(fun)) {
fun <- get(paste0(generic, ".", class), envir = parent.frame())
} else {
stopifnot(is.function(fun))
}
if (isNamespaceLoaded(pkg)) {
registerS3method(generic, class, fun, envir = asNamespace(pkg))
}
# Always register hook in case package is later unloaded & reloaded
setHook(
packageEvent(pkg, "onLoad"),
function(...) {
registerS3method(generic, class, fun, envir = asNamespace(pkg))
}
)
}getRversion — a name the prelude does not declarename: getRversion
.onLoad <- function(libname, pkgname) {
if(getRversion() < "3.6.0") {
register_s3_method("ggplot2", "autoplot", "zoo")
register_s3_method("ggplot2", "fortify", "zoo")
register_s3_method("ggplot2", "scale_type", "yearmon")
register_s3_method("ggplot2", "scale_type", "yearqtr")
}
invisible()
}library.dynam.unload — a name the prelude does not declarename: library.dynam.unload
.onUnload <- function(libpath) {
library.dynam.unload("zoo", libpath)
}