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

Remove Dplyr+Magrittr and Add Poorman #122

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.*\.Rproj
.*\.Rproj\.user
\.gitignore
\.git
\.travis\.yml
cran-comments\.md
README\.Rmd
README-.*\.png
revdep
.*\.Rcheck
^.*\.Rproj$
^\.Rproj\.user$
^\.gitignore$
^\.travis.yml$
^\.travis\.yml$
^cran-comments.md$
^README\.Rmd$
^README-.*\.png$
^xtable_vs_pixiedust.html$
^xtable_vs_pixiedust.Rmd$
^\inst\save_sprinkles_rda.R$
^revdep$
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

# Example code in package build process
*-Ex.R
*.Rcheck

# RStudio files
.Rproj.user/
*.Rproj

# produced vignettes
vignettes/*.html
vignettes/*.pdf
.Rproj.user

# comparisons document
xtable_vs_pixiedust.html
Expand Down
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
Package: pixiedust
Title: Tables so Beautifully Fine-Tuned You Will Believe It's Magic
Version: 0.8.5
Version: 0.9.0
Authors@R: c(person("Benjamin", "Nutter", email = "[email protected]", role = c("aut", "cre")),
person("David", "Kretch", role = c("ctb")))
Author: Benjamin Nutter [aut, cre],
David Kretch [ctb]
Maintainer: Benjamin Nutter <[email protected]>
Description: The introduction of the 'broom' package has made converting model
objects into data frames as simple as a single function. While the 'broom'
package focuses on providing tidy data frames that can be used in advanced
Expand All @@ -17,11 +20,10 @@ Depends:
Imports:
broom,
checkmate (>= 1.8.0),
dplyr,
poorman,
htmltools,
knitr,
labelVector,
magrittr,
scales,
tidyr
Suggests:
Expand All @@ -32,5 +34,5 @@ LazyData: true
VignetteBuilder: knitr
URL: https://github.com/nutterb/pixiedust
BugReports: https://github.com/nutterb/pixiedust/issues
RoxygenNote: 6.0.1
RoxygenNote: 7.1.1
NeedsCompilation: no
17 changes: 7 additions & 10 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
S3method(as.data.frame,dust)
S3method(as.data.frame,dust_list)
S3method(dust,default)
S3method(dust,grouped_df)
S3method(dust,grouped_data)
S3method(dust,list)
S3method(print,dust)
S3method(print,dust_list)
Expand Down Expand Up @@ -75,7 +75,6 @@ S3method(sprinkle_table,default)
S3method(sprinkle_table,dust_list)
S3method(sprinkle_width,default)
S3method(sprinkle_width,dust_list)
export("%<>%")
export("%>%")
export(dust)
export(fixed_header_css)
Expand All @@ -95,7 +94,6 @@ export(pixieply)
export(pvalString)
export(pval_string)
export(redust)
export(sanitize_latex)
export(set_pixie_count)
export(sprinkle)
export(sprinkle_align)
Expand Down Expand Up @@ -131,13 +129,12 @@ export(sprinkle_sanitize)
export(sprinkle_tabcolsep)
export(sprinkle_table)
export(sprinkle_width)
importFrom(dplyr,bind_rows)
importFrom(dplyr,group_by_)
importFrom(dplyr,mutate_)
importFrom(dplyr,select_)
importFrom(dplyr,ungroup)
importFrom(knitr,asis_output)
importFrom(knitr,kable)
importFrom(magrittr,"%<>%")
importFrom(magrittr,"%>%")
importFrom(poorman,"%>%")
importFrom(poorman,bind_rows)
importFrom(poorman,group_by)
importFrom(poorman,mutate)
importFrom(poorman,select)
importFrom(poorman,ungroup)
importFrom(tidyr,spread)
91 changes: 43 additions & 48 deletions R/as.data.frame.dust.R
Original file line number Diff line number Diff line change
@@ -1,106 +1,101 @@
#' @name as.data.frame.dust
#'
#' @title Convert \code{dust} Object to Data Frame
#'
#' @title Convert \code{dust} Object to Data Frame
#' @description Sprinkles are applied to the \code{dust} object
#' as if it were being prepared for printing to the console.
#' However, instead of printing, the object is returned
#' However, instead of printing, the object is returned
#' as a single data frame.
#'
#'
#' @param x A \code{dust} object.
#' @param ... Arguments to be passed to other methods. Currently unused.
#' @param sprinkled Logical. If \code{TRUE}, the sprinkles attached to the
#' \code{dust} object are applied before returning the data frame.
#' \code{dust} object are applied before returning the data frame.
#' Sprinkles are applied via the same mechanism that prints to the console,
#' so only sprinkles that are applicable to console output are used.
#' When \code{FALSE}, \code{pixiedust} attempts to reconstruct the
#' data frame (or tidied output from \code{broom::tidy}
#' When \code{FALSE}, \code{pixiedust} attempts to reconstruct the
#' data frame (or tidied output from \code{broom::tidy}
#' originally given to \code{dust}.
#'
#'
#' @details In its current state, this can be a fairly inefficient function
#' as the table, if the longtable option is in use, will be built in
#' a \code{for} loop and bound together using \code{rbind}. This isn't
#' really intended for large tables, but may be of assistance when
#' there isn't a sprinkle that does what you want to do. (You can
#' at least pull out the object as a data frame and do your own
#' as the table, if the longtable option is in use, will be built in
#' a \code{for} loop and bound together using \code{rbind}. This isn't
#' really intended for large tables, but may be of assistance when
#' there isn't a sprinkle that does what you want to do. (You can
#' at least pull out the object as a data frame and do your own
#' post processing).
#'
#'
#' @author Benjamin Nutter
#'
#' @section Functional Requirements:
#'
#' @section Functional Requirements:
#' \enumerate{
#' \item Accepts an object of class \code{dust} or \code{dust_list}
#' \item Accepts a \code{logical(1)} indicating if the sprinkles should
#' be applied to the data.
#' \item For a \code{dust} object, returns an object of class
#' \item For a \code{dust} object, returns an object of class
#' \code{data.frame}
#' \item For a \code{dust_list} object, returns a list of objects of class
#' \code{data.frame}
#' }
#'
#' @examples
#'
#' @examples
#' fit <- lm(mpg ~ qsec + factor(am) + wt * factor(gear), data = mtcars)
#' Dust <- dust(fit) %>%
#' sprinkle(cols = 2:4, round = 2) %>%
#' sprinkle(cols = 5, fn = quote(pvalString(value))) %>%
#' sprinkle(cols = 3, font_color = "#DA70D6") %>%
#' sprinkle_print_method("html")
#'
#'
#' as.data.frame(Dust)
#'
#'
#' @export

as.data.frame.dust <- function(x, ..., sprinkled = TRUE)
{
as.data.frame.dust <- function(x, ..., sprinkled = TRUE) {
coll <- checkmate::makeAssertCollection()

checkmate::assert_class(x = x,
classes = "dust",
add = coll)

checkmate::assert_logical(x = sprinkled,
len = 1,
add = coll)

checkmate::reportAssertions(coll)


if (sprinkled)
{

if (sprinkled) {
return(print_dust_console(x, return_df = TRUE))
}
else
{
X <- dplyr::select(x$body,
else {
X <- poorman::select(x$body,
row, col, value) %>%
tidyr::spread(col, value) %>%
dplyr::select(-row)
col_names <- dplyr::group_by(x$body, col) %>%
dplyr::summarise(col_name = col_name[1])
tidyr::spread(col, value) %>%
poorman::select(-row)

col_names <- poorman::group_by(x$body, col) %>%
poorman::summarise(col_name = col_name[1])
col_names <- col_names$col_name
names(X) <- col_names
classes <- dplyr::group_by(x$body, col) %>%
dplyr::summarise(col_class = col_class[1])

classes <- poorman::group_by(x$body, col) %>%
poorman::summarise(col_class = col_class[1])
classes <- sprintf("as.%s", classes$col_class)
for (i in seq_along(X)){

for (i in seq_along(X)) {
X[[i]] <- get(classes[i])(X[[i]])
}

X
}

}

#' @rdname as.data.frame.dust
#' @export

as.data.frame.dust_list <- function(x, ...)
{
as.data.frame.dust_list <- function(x, ...) {
checkmate::assert_class(x = x,
classes = "dust_list")

lapply(x,
as.data.frame.dust,
...)
Expand Down
26 changes: 5 additions & 21 deletions R/chain.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
#' @name %>%
#' @rdname chain
#' @importFrom magrittr %>%
#' @importFrom poorman %>%
#' @export %>%
#' @usage lhs \%>\% rhs
#'
#' @title Chain together multiple operations.
#' @description This is a copy of the documentation for \code{\%>\%} in
#' \code{dplyr}. The copy here is made to conform to CRAN requirements
#' regarding documentation. Please see the \code{dplyr} documenation
#' for the complete and current documentation.
#'
#' @param lhs,rhs A dataset and function to apply to it

NULL

#' @name %<>%
#' @rdname compoundAssignment
#' @importFrom magrittr %<>%
#' @export %<>%
#' @usage lhs \%<>\% rhs
#'
#' @title Chain together multiple operations.
#' @description This is a copy of the documentation for \code{\%<>\%} in
#' \code{magrittr}. The copy here is made to conform to CRAN requirements
#' regarding documentation. Please see the \code{magrittr} documenation
#' @description This is a copy of the documentation for \code{\%>\%} in
#' \code{poorman}. The copy here is made to conform to CRAN requirements
#' regarding documentation. Please see the \code{poorman} documenation
#' for the complete and current documentation.
#'
#' @param lhs,rhs A dataset and function to apply to it

NULL
NULL
Loading