-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/26-remove-src-tbl'. Fixes #26.
- Functions related to `tbl` and `src` stay in `dplyr` (#26).
- Loading branch information
Showing
14 changed files
with
13 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,19 @@ Authors@R: c( person("Hadley", "Wickham", , "[email protected]", role | |
person("RStudio", role = "cph") ) | ||
URL: https://github.com/krlmlr/tibble | ||
BugReports: https://github.com/krlmlr/tibble/issues | ||
Depends: R (>= 3.1.2) | ||
Imports: methods, assertthat, utils, lazyeval (>= 0.1.10), Rcpp | ||
Suggests: testthat, knitr, Lahman (>= 3.0.1) | ||
Depends: | ||
R (>= 3.1.2) | ||
Imports: | ||
methods, | ||
assertthat, | ||
utils, | ||
lazyeval (>= 0.1.10), | ||
Rcpp | ||
Suggests: | ||
testthat, | ||
knitr, | ||
Lahman (>= 3.0.1) | ||
LazyData: yes | ||
License: MIT + file LICENSE | ||
RoxygenNote: 5.0.1.9000 | ||
RoxygenNote: 5.0.1 | ||
LinkingTo: Rcpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +0,0 @@ | ||
#' A local source. | ||
#' | ||
#' This is mainly useful for testing, since makes it possible to refer to | ||
#' local and remote tables using exactly the same syntax. | ||
#' | ||
#' Generally, \code{src_local} should not be called directly, but instead | ||
#' \code{tbl_df} should be used. | ||
#' | ||
#' @param tbl name of the function used to generate \code{tbl} objects | ||
#' @param pkg,env Either the name of a package or an environment object in | ||
#' which to look for objects. | ||
#' @keywords internal | ||
#' @export | ||
#' @examples | ||
#' if (require("Lahman")) { | ||
#' src_df("Lahman") | ||
#' | ||
#' batting_df <- tbl(src_df("Lahman"), "Batting") | ||
#' } | ||
src_local <- function(tbl, pkg = NULL, env = NULL) { | ||
if (!xor(is.null(pkg), is.null(env))) { | ||
stop("Must supply exactly one of pkg and env", call. = FALSE) | ||
} | ||
if (!is.null(pkg)) { | ||
env <- getNamespaceInfo(pkg, "lazydata") | ||
name <- paste0("<package: ", pkg, ">") | ||
} else { | ||
name <- utils::capture.output(print(env)) | ||
} | ||
|
||
src("local", tbl_f = match.fun(tbl), name = name, env = env) | ||
} | ||
|
||
#' @rdname src_local | ||
#' @export | ||
src_df <- function(pkg = NULL, env = NULL) { | ||
src_local("tbl_df", pkg, env) | ||
} | ||
|
||
#' @export | ||
src_tbls.src_local <- function(x, ...) { | ||
objs <- ls(envir = x$env) | ||
Filter(function(obj) is.data.frame(get(obj, envir = x$env)), objs) | ||
} | ||
|
||
#' @export | ||
tbl.src_local <- function(src, from, ...) { | ||
src$tbl_f(get(from, src$env)) | ||
} | ||
|
||
#' @export | ||
format.src_local <- function(x, width = NULL, ...) { | ||
width <- width %||% getOption("width") | ||
paste0("src: ", x$name, "\n", | ||
wrap("tbls: ", paste0(sort(src_tbls(x)), collapse = ", "), width = width)) | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +0,0 @@ | ||
#' Create a "src" object | ||
#' | ||
#' \code{src} is the standard constructor for srcs and \code{is.src} tests. | ||
#' | ||
#' @keywords internal | ||
#' @export | ||
#' @param subclass name of subclass. "src" is an abstract base class, so you | ||
#' must supply this value. \code{src_} is automatically prepended to the | ||
#' class name | ||
#' @param ... fields used by object | ||
#' @param x object to test for "src"-ness. | ||
src <- function(subclass, ...) { | ||
subclass <- paste0("src_", subclass) | ||
structure(list(...), class = c(subclass, "src")) | ||
} | ||
|
||
#' @rdname src | ||
#' @export | ||
is.src <- function(x) inherits(x, "src") | ||
|
||
#' @export | ||
print.src <- function(x, ...) { | ||
cat(format(x, ...), "\n", sep = "") | ||
} | ||
|
||
#' List all tbls provided by a source. | ||
#' | ||
#' This is a generic method which individual src's will provide methods for. | ||
#' Most methods will not be documented because it's usually pretty obvious what | ||
#' possible results will be. | ||
#' | ||
#' @param x a data src. | ||
#' @export | ||
src_tbls <- function(x) { | ||
UseMethod("src_tbls") | ||
} | ||
|
||
#' Figure out if two sources are the same (or two tbl have the same source) | ||
#' | ||
#' @param x,y src or tbls to test | ||
#' @return a logical flag | ||
#' @export | ||
#' @keywords internal | ||
same_src <- function(x, y) { | ||
UseMethod("same_src") | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.