spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From felixcheung <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-10913][SPARKR] attach() function suppor...
Date Sat, 10 Oct 2015 18:13:34 GMT
Github user felixcheung commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9031#discussion_r41699843
  
    --- Diff: R/pkg/R/DataFrame.R ---
    @@ -1881,3 +1881,33 @@ setMethod("as.data.frame",
                 }
                 collect(x)
               })
    +
    +#' The specified DataFrame is attached to the R search path. This means that
    +#' the DataFrame is searched by R when evaluating a variable, so columns in
    +#' the DataFrame can be accessed by simply giving their names.
    +#'
    +#' @rdname attach
    +#' @title Attach DataFrame to R search path
    +#' @param what (DataFrame) The DataFrame to attach
    +#' @param pos (integer) Specify position in search() where to attach.
    +#' @param name (character) Name to use for the attached DataFrame. Names
    +#'   starting with package: are reserved for library.
    +#' @param warn.conflicts (logical) If TRUE, warnings are printed about conflicts
    +#' from attaching the database, unless that DataFrame contains an object
    +#' @examples
    +#' \dontrun{
    +#' attach(irisDf)
    +#' summary(Sepal_Width)
    +#' }
    +#' @seealso \link{detach}
    +setMethod("attach",
    +          signature(what = "DataFrame"),
    +          function(what, pos = 2, name = deparse(substitute(what)), warn.conflicts =
TRUE) {
    +            bf <- what
    +            cols <- columns(bf)
    +            newEnv <- new.env()
    +            for (i in 1:length(cols)) {
    --- End diff --
    
    I'm not sure we can do that now from R:
    ```
    > a <- list()
    > b <- createDataFrame(sqlContext, a)
    Error in take(x, 1)[[1]] : subscript out of bounds
    
    > a <- data.frame()
    > a
    data frame with 0 columns and 0 rows
    > b <- createDataFrame(sqlContext, a)
    Error in FUN(X[[i]], ...) : can not infer type from NULL
    ```
    
    Or 0-col DataFrame being very useful?
    Though I agree we could check for it, in case that support is added in the future. I'd
suggest either adding a `stopifnot()` or a test case for that?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message