-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Head and Tail methods #176
base: master
Are you sure you want to change the base?
Changes from all commits
2476796
152c35e
640614d
0c8450a
78051c2
5184c12
aa61fbb
81125b2
2184aef
4a6f72e
a69ad2f
01f9583
8b137c2
a0fdefb
a28a5bc
dfe99d3
693854d
cafa278
cea88d8
69475cf
7c28671
6579581
3e126e1
8f2291a
5c9ba02
8887137
903260d
18d113f
94d0f83
cecdd64
adc5bbc
297d424
2e8dde1
d51d9ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ as.data.frame.CrunchDataFrame <- function (x, | |
ds <- attr(x, "crunchDataset") | ||
tmp <- tempfile() | ||
on.exit(unlink(tmp)) | ||
write.csv(ds, tmp, categorical = "id") | ||
tmp <- write.csv(ds, tmp, categorical = "id") | ||
# TODO: use variableMetadata to provide all `colClasses`? | ||
# meta <- variableMetadata(ds) | ||
ds_out <- read.csv(tmp, stringsAsFactors = FALSE) | ||
|
@@ -192,3 +192,48 @@ as.data.frame.FilterCatalog <- function (x, | |
...) { | ||
catalogToDataFrame(x, keys = keys, row.names = row.names, ...) | ||
} | ||
|
||
#' Head and tail methods for Crunch objects. See [utils::head()] for more details. | ||
#' | ||
#' @param x a CrunchDataset, CrunchDataFrame, or CrunchVariable | ||
#' @param n a single integer representing the length of the returning object. | ||
#' @param ... ignored | ||
#' @name head-tail | ||
#' @aliases head tail | ||
NULL | ||
|
||
#' @rdname head-tail | ||
#' @export | ||
setMethod("head", "CrunchDataset", function (x, n=6L, ...) { | ||
as.data.frame(x[head(seq_len(nrow(x)), n),], force=TRUE) | ||
}) | ||
|
||
#' @rdname head-tail | ||
#' @export | ||
setMethod("head", "CrunchDataFrame", function (x, n=6L, ...) { | ||
return(head(attr(x, "crunchDataset"))) | ||
}) | ||
|
||
#' @rdname head-tail | ||
#' @export | ||
setMethod("head", "CrunchVariable", function (x, n=6L, ...) { | ||
as.vector(x[head(seq_len(length(x)), n)], ...) | ||
}) | ||
|
||
#' @rdname head-tail | ||
#' @export | ||
setMethod("tail", "CrunchDataset", function (x, n=6L, ...) { | ||
as.data.frame(x[tail(seq_len(nrow(x)), n),], force=TRUE) | ||
}) | ||
|
||
#' @rdname head-tail | ||
#' @export | ||
setMethod("tail", "CrunchDataFrame", function (x, n=6L, ...) { | ||
return(tail(attr(x, "crunchDataset"))) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like these would respect the ordering of the CrunchDataFrame which is in the I don't think it would be too difficult to add that, though we haven't been using that feature too much (it was designed to make merging onto simple feature style geographies possible, but I haven't had the time to push forward on that recently) |
||
|
||
#' @rdname head-tail | ||
#' @export | ||
setMethod("tail", "CrunchVariable", function (x, n=6L, ...) { | ||
as.vector(x[tail(seq_len(length(x)), n)]) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
structure(list(url = "https://app.crunch.io/api/datasets/1/export/csv/", | ||
status_code = 202L, headers = structure(list(allow = "GET, HEAD, OPTIONS, POST", | ||
`content-encoding` = "gzip", `content-type` = "application/json;charset=utf-8", | ||
date = "Fri, 12 Jan 2018 14:23:13 GMT", location = "dataset_exports/test-ds.csv?Signature=SKknqNLKd2vJu3EcxKhOJxOjp4c%3D&Expires=1515770593&AWSAccessKeyId=AKIAJT4CEBNJXNPF3NZA", | ||
server = "nginx", `set-cookie` = "REDACTED", vary = "Cookie, Accept-Encoding", | ||
`x-timing` = "", `content-length` = "141", connection = "keep-alive"), .Names = c("allow", | ||
"content-encoding", "content-type", "date", "location", "server", | ||
"set-cookie", "vary", "x-timing", "content-length", "connection" | ||
), class = c("insensitive", "list")), all_headers = list( | ||
structure(list(status = 202L, version = "HTTP/1.1", headers = structure(list( | ||
allow = "GET, HEAD, OPTIONS, POST", `content-encoding` = "gzip", | ||
`content-type` = "application/json;charset=utf-8", | ||
date = "Fri, 12 Jan 2018 14:23:13 GMT", location = "dataset_exports/test-ds.csv?Signature=SKknqNLKd2vJu3EcxKhOJxOjp4c%3D&Expires=1515770593&AWSAccessKeyId=AKIAJT4CEBNJXNPF3NZA", | ||
server = "nginx", `set-cookie` = "REDACTED", vary = "Cookie, Accept-Encoding", | ||
`x-timing` = "", `content-length` = "141", connection = "keep-alive"), .Names = c("allow", | ||
"content-encoding", "content-type", "date", "location", | ||
"server", "set-cookie", "vary", "x-timing", "content-length", | ||
"connection"), class = c("insensitive", "list"))), .Names = c("status", | ||
"version", "headers"))), cookies = structure(list(domain = ".crunch.io", | ||
flag = TRUE, path = "/", secure = FALSE, expiration = structure(1547302993, class = c("POSIXct", | ||
"POSIXt")), name = "token", value = "REDACTED"), .Names = c("domain", | ||
"flag", "path", "secure", "expiration", "name", "value"), row.names = c(NA, | ||
-1L), class = "data.frame"), content = as.raw(c(0x7b, 0x22, | ||
0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x3a, 0x20, | ||
0x22, 0x73, 0x68, 0x6f, 0x6a, 0x69, 0x3a, 0x76, 0x69, 0x65, | ||
0x77, 0x22, 0x2c, 0x20, 0x22, 0x73, 0x65, 0x6c, 0x66, 0x22, | ||
0x3a, 0x20, 0x22, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, | ||
0x2f, 0x61, 0x70, 0x70, 0x2e, 0x63, 0x72, 0x75, 0x6e, 0x63, | ||
0x68, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x64, | ||
0x61, 0x74, 0x61, 0x73, 0x65, 0x74, 0x73, 0x2f, 0x34, 0x31, | ||
0x36, 0x32, 0x32, 0x35, 0x61, 0x35, 0x63, 0x38, 0x38, 0x37, | ||
0x34, 0x33, 0x66, 0x65, 0x61, 0x30, 0x37, 0x65, 0x62, 0x36, | ||
0x38, 0x31, 0x31, 0x37, 0x63, 0x61, 0x34, 0x37, 0x61, 0x64, | ||
0x2f, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x63, 0x73, | ||
0x76, 0x2f, 0x22, 0x2c, 0x20, 0x22, 0x76, 0x61, 0x6c, 0x75, | ||
0x65, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x74, 0x74, 0x70, 0x73, | ||
0x3a, 0x2f, 0x2f, 0x61, 0x70, 0x70, 0x2e, 0x63, 0x72, 0x75, | ||
0x6e, 0x63, 0x68, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, | ||
0x2f, 0x70, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x2f, | ||
0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x2f, 0x22, 0x7d | ||
)), date = structure(1515766993, class = c("POSIXct", "POSIXt" | ||
), tzone = "GMT"), times = structure(c(0, 0.129607, 0.23883, | ||
0.501342, 0.629068, 0.629116), .Names = c("redirect", "namelookup", | ||
"connect", "pretransfer", "starttransfer", "total")), request = structure(list( | ||
method = "POST", url = "https://app.crunch.io/api/datasets/1/export/csv/", | ||
headers = structure(c("application/json, text/xml, application/xml, */*", | ||
"", "libcurl/7.54.0 curl/3.0 httr/1.3.1 rcrunch/1.19.1" | ||
), .Names = c("Accept", "Content-Type", "user-agent")), | ||
fields = NULL, options = structure(list(useragent = "libcurl/7.54.0 r-curl/3.0 httr/1.3.1", | ||
post = TRUE, postfieldsize = 131L, postfields = as.raw(c(0x7b, | ||
0x22, 0x66, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x22, 0x3a, | ||
0x7b, 0x22, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, | ||
0x6e, 0x22, 0x3a, 0x22, 0x62, 0x65, 0x74, 0x77, 0x65, | ||
0x65, 0x6e, 0x22, 0x2c, 0x22, 0x61, 0x72, 0x67, 0x73, | ||
0x22, 0x3a, 0x5b, 0x7b, 0x22, 0x66, 0x75, 0x6e, 0x63, | ||
0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x22, 0x72, 0x6f, | ||
0x77, 0x22, 0x2c, 0x22, 0x61, 0x72, 0x67, 0x73, 0x22, | ||
0x3a, 0x5b, 0x5d, 0x7d, 0x2c, 0x7b, 0x22, 0x76, 0x61, | ||
0x6c, 0x75, 0x65, 0x22, 0x3a, 0x30, 0x7d, 0x2c, 0x7b, | ||
0x22, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3a, 0x36, | ||
0x7d, 0x5d, 0x7d, 0x2c, 0x22, 0x6f, 0x70, 0x74, 0x69, | ||
0x6f, 0x6e, 0x73, 0x22, 0x3a, 0x7b, 0x22, 0x75, 0x73, | ||
0x65, 0x5f, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, | ||
0x79, 0x5f, 0x69, 0x64, 0x73, 0x22, 0x3a, 0x74, 0x72, | ||
0x75, 0x65, 0x7d, 0x7d)), postredir = 3), .Names = c("useragent", | ||
"post", "postfieldsize", "postfields", "postredir")), | ||
output = structure(list(), class = c("write_memory", | ||
"write_function"))), .Names = c("method", "url", "headers", | ||
"fields", "options", "output"), class = "request")), .Names = c("url", | ||
"status_code", "headers", "all_headers", "cookies", "content", | ||
"date", "times", "request"), class = "response") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"element": | ||
"shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1/summary/?filter=%7B%22function%22%3A%22between%22%2C%22args%22%3A%5B%7B%22function%22%3A%22row%22%2C%22args%22%3A%5B%5D%7D%2C%7B%22value%22%3A19%7D%2C%7B%22value%22%3A25%7D%5D%7D", | ||
"value": { | ||
"unweighted": { | ||
"filtered": 6, | ||
"total": 25 | ||
}, | ||
"variables": 6, | ||
"weighted": { | ||
"filtered": 6, | ||
"total": 25 | ||
}, | ||
"columns": 6 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1/summary/?filter=%7B%22function%22%3A%22between%22%2C%22args%22%3A%5B%7B%22function%22%3A%22row%22%2C%22args%22%3A%5B%5D%7D%2C%7B%22value%22%3A0%7D%2C%7B%22value%22%3A6%7D%5D%7D", | ||
"value": { | ||
"unweighted": { | ||
"filtered": 6, | ||
"total": 25 | ||
}, | ||
"variables": 6, | ||
"weighted": { | ||
"filtered": 6, | ||
"total": 25 | ||
}, | ||
"columns": 6 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1/variables/gender/values/?filter=%7B%22function%22%3A%22between%22%2C%22args%22%3A%5B%7B%22function%22%3A%22row%22%2C%22args%22%3A%5B%5D%7D%2C%7B%22value%22%3A0%7D%2C%7B%22value%22%3A6%7D%5D%7D&offset=0&limit=5000", | ||
"value": ["w", "n", "x", "b", "q", "s"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1/variables/gender/values/?filter=%7B%22function%22%3A%22between%22%2C%22args%22%3A%5B%7B%22function%22%3A%22row%22%2C%22args%22%3A%5B%5D%7D%2C%7B%22value%22%3A0%7D%2C%7B%22value%22%3A4%7D%5D%7D&offset=0&limit=200000", | ||
"value": [2, 2, {"?": -1}, 2] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1/variables/starttime/values/?filter=%7B%22function%22%3A%22in%22%2C%22args%22%3A%5B%7B%22function%22%3A%22row%22%2C%22args%22%3A%5B%5D%7D%2C%7B%22column%22%3A%5B0%2C17%5D%7D%5D%7D&offset=0&limit=100000", | ||
"value": ["1956-02-13", "1956-01-28"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1/variables/starttime/values/?filter=%7B%22function%22%3A%22in%22%2C%22args%22%3A%5B%7B%22function%22%3A%22row%22%2C%22args%22%3A%5B%5D%7D%2C%7B%22column%22%3A%5B0%2C1%2C16%2C17%5D%7D%5D%7D&offset=0&limit=100000", | ||
"value": ["1956-02-13", "1955-12-28", "1955-12-30", "1956-01-28"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1/variables/starttime/values/?filter=%7B%22function%22%3A%22between%22%2C%22args%22%3A%5B%7B%22function%22%3A%22row%22%2C%22args%22%3A%5B%5D%7D%2C%7B%22value%22%3A0%7D%2C%7B%22value%22%3A25%7D%5D%7D&offset=0&limit=100000", | ||
"value": ["1956-02-13", "1955-12-28", "1955-11-17", "1956-02-08", "1956-01-17", "1956-01-21", "1956-02-07", "1955-12-25", "1956-01-17", "1955-12-12", "1955-11-21", "1955-12-06", "1956-01-19", "1955-12-15", "1956-02-07", "1956-02-08", "1955-12-30", "1956-01-28", "1956-01-01", "1956-01-15", "1955-11-13", "1955-11-17", "1955-11-09", "1955-12-22", "1955-12-20"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1/variables/textVar/values/?filter=%7B%22function%22%3A%22between%22%2C%22args%22%3A%5B%7B%22function%22%3A%22row%22%2C%22args%22%3A%5B%5D%7D%2C%7B%22value%22%3A0%7D%2C%7B%22value%22%3A25%7D%5D%7D&offset=0&limit=5000", | ||
"value": ["w", "n", "x", "b", "q", "s", "l", "v", "v", "y", "m", "t", "s", "e", "z", "k", "n", "w", "v", "i", "h", "z", "m", "c", "x"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1/variables/textVar/values/?filter=%7B%22function%22%3A%22between%22%2C%22args%22%3A%5B%7B%22function%22%3A%22row%22%2C%22args%22%3A%5B%5D%7D%2C%7B%22value%22%3A0%7D%2C%7B%22value%22%3A6%7D%5D%7D&offset=0&limit=5000", | ||
"value": ["w", "n", "x", "b", "q", "s"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1/variables/textVar/values/?filter=%7B%22function%22%3A%22between%22%2C%22args%22%3A%5B%7B%22function%22%3A%22row%22%2C%22args%22%3A%5B%5D%7D%2C%7B%22value%22%3A19%7D%2C%7B%22value%22%3A25%7D%5D%7D&offset=0&limit=5000", | ||
"value": ["i", "h", "z", "m", "c", "x"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1/variables/textVar/values/?filter=%7B%22function%22%3A%22in%22%2C%22args%22%3A%5B%7B%22function%22%3A%22row%22%2C%22args%22%3A%5B%5D%7D%2C%7B%22column%22%3A%5B0%2C17%5D%7D%5D%7D&offset=0&limit=5000", "value": ["w", "w"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1/variables/textVar/values/?filter=%7B%22function%22%3A%22in%22%2C%22args%22%3A%5B%7B%22function%22%3A%22row%22%2C%22args%22%3A%5B%5D%7D%2C%7B%22column%22%3A%5B0%2C1%2C16%2C17%5D%7D%5D%7D&offset=0&limit=5000", | ||
"value": ["w", "n", "n", "w"]} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"element": "shoji:view", | ||
"self": "https://app.crunch.io/api/datasets/1streaming/summary/?filter=%7B%7D", | ||
"value": { | ||
"unweighted": { | ||
"filtered": 25, | ||
"total": 25}, | ||
"variables": 6, | ||
"weighted": { | ||
"filtered": 25, | ||
"total": 25}, | ||
"columns": 6} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"element": "shoji:view", "self": "https://app.crunch.io/api/progress/success/", "views": {"result": "https://app.crunch.io/api/progress/success/result/"}, "value": {"progress": 100, "message": "complete"}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the
head
/tail
methods that we are imitating are based on S3 classes, we should probably match those and define this (and similar for the following method definitions) as:head.CrunchDataset <- function ...
Then remove the lines in AllGenerics.R that make the generics. This will prevent masking when the package is loaded.