Skip to content
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

use_as_rownames function #8 #11

Merged
merged 11 commits into from
Mar 8, 2016
Merged

use_as_rownames function #8 #11

merged 11 commits into from
Mar 8, 2016

Conversation

zhilongjia
Copy link
Contributor

use_as_rownames function returns data.frame, not tbl, with rownames. This is to solve issue #8.

Closes #8.

Closes #28.

@@ -200,6 +200,34 @@ add_rownames <- function(df, var = "rowname") {
as_data_frame(cbind(rn, df))
}

#' Convert a column of tbl into rownames of data.frame.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if the two functions were documented together (via @rdname).

@codecov-io
Copy link

Current coverage is 96.57%

Merging #11 into master will increase coverage by +0.13% as of f2e0c32

@@            master     #11   diff @@
======================================
  Files           11      11       
  Stmts          422     438    +16
  Branches         0       0       
  Methods          0       0       
======================================
+ Hit            407     423    +16
  Partial          0       0       
  Missed          15      15       

Review entire Coverage Diff as of f2e0c32

Powered by Codecov. Updated on successful CI builds.

stop(paste("No", var, "column in the colnames.") )
}

df <- as.data.frame(df)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is intended behavior, it should be documented, but I wonder if it's necessary. (One can always write use_as_rownames() %>% as.data.frame or the other way round, if necessary.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least to me, use_as_rownames is to interact with the base::data.frame and tbl is trying to avoid rownames. So I convert it into data.frame directly. Comments?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense; still, needs to be documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not get meaning of to be documented. Return a data.frame is documented in details now. Correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed that, sorry.

@zhilongjia
Copy link
Contributor Author

add_rownames keeps row names of data frame (Probably it affects a lots). And it will stop if there is a var column names in the input data frame.

More tests are added (I use test a few. Maybe need update).

use_as_rownames will update the row names using var whether it exists or not,then delete the var column. And it returns data.frame so far.

#' Convert row names to an explicit variable.
#' Converting between rownames and a column
#'
#' add_rownames: Convert row names to an explicit variable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go into the @details section

@krlmlr
Copy link
Member

krlmlr commented Dec 18, 2015

Thanks. This looks good, I'll merge it soon.

@@ -25,4 +25,4 @@ Suggests:
Lahman (>= 3.0.1)
LazyData: yes
License: MIT + file LICENSE
RoxygenNote: 5.0.1.9000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spurious change prevents me from merging into master.

}

#' @rdname rownames
#' @export
rownames_to_column <- add_rownames
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new function isn't supposed to convert to tbl_df. Let's remove add_rownames() altogether and keep it only in dplyr for compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rownames_to_column is a copy of add_rownames. So you mean keep the input of rownames_to_column as it is (I did not change that section)? For example, input data.frame output data.frame? I will remove add_rownames.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, data.frame -> data.frame, tbl_df -> tbl_df. Thanks.

@krlmlr krlmlr removed the question label Mar 2, 2016
}

#' \code{column_to_rownames} convert a column variable to row names. This is an
#' inverted operation of rownames_to_column.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\code{rownames_to_column}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description is for column_to_rownames. Why \code{rownames_to_column} ?

@krlmlr
Copy link
Member

krlmlr commented Mar 2, 2016

Thanks. Could you please merge/rebase?

krlmlr added a commit that referenced this pull request Mar 8, 2016
- New `rownames_to_column()` and `column_to_rownames()` functions, replace `add_rownames()` (#11, @zhilongjia).
@krlmlr krlmlr merged commit f5012b7 into tidyverse:master Mar 8, 2016
@krlmlr
Copy link
Member

krlmlr commented Mar 8, 2016

Thanks! I'll tweak documentation and tests myself.

krlmlr pushed a commit that referenced this pull request Mar 8, 2016
- `frame_data()` now also creates a list column if one of the entries is a list (#32).
- New `rownames_to_column()` and `column_to_rownames()` functions, replace `add_rownames()` (#11, @zhilongjia).
krlmlr pushed a commit that referenced this pull request Mar 10, 2016
- Features
    - New `as_data_frame.table()` with argument `n` to control name of count column (#22, #23).
    - New function `repair_names()` fixes missing and duplicate names (#10, #15, @r2evans).
    - `frame_data()` now also creates a list column if one of the entries is a list (#32).
    - New `rownames_to_column()` and `column_to_rownames()` functions, replace `add_rownames()` (#11, @zhilongjia).
    - Use `tibble` prefix for options (#13, #36).

- Documentation
    - Add pre-tibble NEWS (#39, #40).
    - Include vignette (#38).
    - Expand README.
    - Fix typos in documentation.
    - Remove use of `src()` from examples.

- Prepare CRAN release
    - Use new-style `.travis.yml`
    - Use AppVeyor for testing.
    - Finer coverage analysis (#37).
    - Check with win-builder and valgrind.
    - Fix NOTE from `R CMD check`.
krlmlr pushed a commit that referenced this pull request Mar 22, 2016
- Initial CRAN release

- Extracted from `dplyr` 0.4.3

- Exported functions:
    - `tbl_df()`
    - `as_data_frame()`
    - `data_frame()`, `data_frame_()`
    - `frame_data()`, `tibble()`
    - `glimpse()`
    - `trunc_mat()`, `knit_print.trunc_mat()`
    - `type_sum()`
    - New `lst()` and `lst_()` create lists in the same way that
      `data_frame()` and `data_frame_()` create data frames (tidyverse/dplyr#1290).
      `lst(NULL)` doesn't raise an error (#17, @jennybc), but always
      uses deparsed expression as name (even for `NULL`).
    - New `add_row()` makes it easy to add a new row to data frame
      (tidyverse/dplyr#1021).
    - New `rownames_to_column()` and `column_to_rownames()` (#11, @zhilongjia).
    - New `has_rownames()` and `remove_rownames()` (#44).
    - New `repair_names()` fixes missing and duplicate names (#10, #15,
      @r2evans).
    - New `is_vector_s3()`.

- Features
    - New `as_data_frame.table()` with argument `n` to control name of count
      column (#22, #23).
    - Use `tibble` prefix for options (#13, #36).
    - `glimpse()` now (invisibly) returns its argument (tidyverse/dplyr#1570). It
      is now a generic, the default method dispatches to `str()`
      (tidyverse/dplyr#1325).  The default width is obtained from the
      `tibble.width` option (#35, #56).
    - `as_data_frame()` is now an S3 generic with methods for lists (the old
      `as_data_frame()`), data frames (trivial), matrices (with efficient
      C++ implementation) (tidyverse/dplyr#876), and `NULL` (returns a 0-row
      0-column data frame) (#17, @jennybc).
    - Non-scalar input to `frame_data()` and `tibble()` (including lists)
      creates list-valued columns (#7). These functions return 0-row but n-col
      data frame if no data.

- Bug fixes
    - `frame_data()` properly constructs rectangular tables (tidyverse/dplyr#1377,
      @kevinushey).

- Minor modifications
    - Uses `setOldClass(c("tbl_df", "tbl", "data.frame"))` to help with S4
      (tidyverse/dplyr#969).
    - `tbl_df()` automatically generates column names (tidyverse/dplyr#1606).
    - `tbl_df`s gain `$` and `[[` methods that are ~5x faster than the defaults,
      never do partial matching (tidyverse/dplyr#1504), and throw an error if the
      variable does not exist.  `[[.tbl_df()` falls back to regular subsetting
      when used with anything other than a single string (#29).
      `base::getElement()` now works with tibbles (#9).
    - `all_equal()` allows to compare data frames ignoring row and column order,
      and optionally ignoring minor differences in type (e.g. int vs. double)
      (tidyverse/dplyr#821).  Used by `all.equal()` for tibbles.  (This package
      contains a pure R implementation of `all_equal()`, the `dplyr` code has
      identical behavior but is written in C++ and thus faster.)
    - The internals of `data_frame()` and `as_data_frame()` have been aligned,
      so `as_data_frame()` will now automatically recycle length-1 vectors.
      Both functions give more informative error messages if you are attempting
      to create an invalid data frame.  You can no longer create a data frame
      with duplicated names (tidyverse/dplyr#820).  Both functions now check that
      you don't have any `POSIXlt` columns, and tell you to use `POSIXct` if you
      do (tidyverse/dplyr#813).  `data_frame(NULL)` raises error "must be a 1d
      atomic vector or list".
    - `trunc_mat()` and `print.tbl_df()` are considerably faster if you have
      very wide data frames.  They will now also only list the first 100
      additional variables not already on screen - control this with the new
      `n_extra` parameter to `print()` (tidyverse/dplyr#1161).  The type of list
      columns is printed correctly (tidyverse/dplyr#1379).  The `width` argument is
      used also for 0-row or 0-column data frames (#18).
    - When used in list-columns, S4 objects only print the class name rather
      than the full class hierarchy (#33).
    - Add test that `[.tbl_df()` does not change class (#41, @jennybc).  Improve
      `[.tbl_df()` error message.

- Documentation
    - Update README, with edits (#52, @bhive01) and enhancements (#54,
      @jennybc).
    - `vignette("tibble")` describes the difference between tbl_dfs and
      regular data frames (tidyverse/dplyr#1468).

- Code quality
    - Test using new-style Travis-CI and AppVeyor. Full test coverage (#24,
      #53). Regression tests load known output from file (#49).
    - Renamed `obj_type()` to `obj_sum()`, improvements, better integration with
     `type_sum()`.
    - Internal cleanup.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove add_rownames() add_rownames enhancement
4 participants