Skip to content

Commit

Permalink
Merge branch 'feature/26-remove-src-tbl'. Fixes #26.
Browse files Browse the repository at this point in the history
- Functions related to `tbl` and `src` stay in `dplyr` (#26).
  • Loading branch information
Kirill Müller committed Feb 29, 2016
2 parents 13b0e49 + f45521b commit 7548971
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 336 deletions.
17 changes: 13 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 0 additions & 18 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ S3method("[",tbl_df)
S3method("[[",tbl_df)
S3method(all.equal,tbl_df)
S3method(as.data.frame,tbl_df)
S3method(as.tbl,data.frame)
S3method(as.tbl,tbl)
S3method(as_data_frame,"NULL")
S3method(as_data_frame,data.frame)
S3method(as_data_frame,list)
S3method(as_data_frame,matrix)
S3method(as_data_frame,tbl_df)
S3method(format,src_local)
S3method(format_v,character)
S3method(format_v,default)
S3method(glimpse,data.frame)
Expand All @@ -22,13 +19,8 @@ S3method(obj_type,"NULL")
S3method(obj_type,data.frame)
S3method(obj_type,data_frame)
S3method(obj_type,default)
S3method(print,src)
S3method(print,tbl_df)
S3method(print,trunc_mat)
S3method(same_src,data.frame)
S3method(src_tbls,src_local)
S3method(tbl,src_local)
S3method(tbl_vars,data.frame)
S3method(type_sum,Date)
S3method(type_sum,POSIXt)
S3method(type_sum,array)
Expand All @@ -42,26 +34,16 @@ S3method(type_sum,matrix)
S3method(type_sum,numeric)
export(add_row)
export(add_rownames)
export(as.tbl)
export(as_data_frame)
export(data_frame)
export(data_frame_)
export(dim_desc)
export(frame_data)
export(glimpse)
export(is.src)
export(is.tbl)
export(knit_print.trunc_mat)
export(lst)
export(lst_)
export(same_src)
export(src)
export(src_df)
export(src_local)
export(src_tbls)
export(tbl)
export(tbl_df)
export(tbl_vars)
export(tibble)
export(trunc_mat)
export(type_sum)
Expand Down
56 changes: 0 additions & 56 deletions R/src-local.r
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))
}
46 changes: 0 additions & 46 deletions R/src.r
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")
}
13 changes: 0 additions & 13 deletions R/tbl-df.r
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@ tbl_df <- function(data) {
as_data_frame(data)
}

#' @export
as.tbl.data.frame <- function(x, ...) {
tbl_df(x)
}

#' @export
tbl_vars.data.frame <- function(x) names(x)

#' @export
same_src.data.frame <- function(x, y) {
is.data.frame(y)
}

# Standard data frame methods --------------------------------------------------

#' @export
Expand Down
28 changes: 0 additions & 28 deletions R/tbl.r

This file was deleted.

19 changes: 0 additions & 19 deletions man/same_src.Rd

This file was deleted.

25 changes: 0 additions & 25 deletions man/src.Rd

This file was deleted.

34 changes: 0 additions & 34 deletions man/src_local.Rd

This file was deleted.

17 changes: 0 additions & 17 deletions man/src_tbls.Rd

This file was deleted.

25 changes: 0 additions & 25 deletions man/tbl.Rd

This file was deleted.

15 changes: 0 additions & 15 deletions man/tbl_vars.Rd

This file was deleted.

Loading

0 comments on commit 7548971

Please sign in to comment.