Skip to content

Commit

Permalink
Merge pull request #9 from AlissonRP/freq2x2
Browse files Browse the repository at this point in the history
Release 0.3
  • Loading branch information
AlissonRP authored Jan 28, 2022
2 parents 7ad30fb + be15bbb commit 05f609b
Show file tree
Hide file tree
Showing 30 changed files with 369 additions and 191 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v1
with:
extra-packages: rcmdcheck

- uses: r-lib/actions/check-r-package@v1

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
7 changes: 6 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(as_tabyl)
export(pdf1_freq.tbl)
export(pdf1_freq.tbl2)
export(pdf1_na)
export(pdf1_summary)
export(pdf1_tbl)
export(pdf1_tbl_freq)
export(pdf1_tbl_freq2)
export(untabyl)
importFrom(janitor,as_tabyl)
importFrom(janitor,untabyl)
importFrom(magrittr,"%>%")
64 changes: 0 additions & 64 deletions R/as_tabyl.R

This file was deleted.

13 changes: 13 additions & 0 deletions R/freq-table-DE.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' pdf1_freq.tbl
#'
#' this is a very simple frequency table generator
#'
#'
#' @param obj Object used to create the table. Data frame, list or environment
#' (or object coercible by as.data.frame to a data frame)
#' @param tit Title for the table, write in string format
#' @param v Variable that you want the table (not written in string format)
#' @export
pdf1_freq.tbl <- function(obj, v, tit) {
stop("Esta função foi renomeada, use pdf1_tbl_freq")
}
18 changes: 9 additions & 9 deletions R/freq-table.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#' pdf1_freq.tbl
#' pdf1_freq_tbl
#'
#' this is a very simple frequency table generator
#'
#'
#' @param obj Object used to create the table. Data frame, list or environment
#' (or object coercible by as.data.frame to a data frame)
#' @param tit Title for the table, write in string format
#' @param v Variable that you want the table (not written in string format)
#' @param var Variable that you want the table (not written in string format)
#' @param ... Other arguments
#' @examples
#' iris %>%
#' mypdf1::pdf1_freq.tbl(Species, "title") %>%
#' mypdf1::pdf1_tbl_freq(Species) %>%
#' mypdf1::pdf1_tbl(" You can combine this function too!")
#' @export
pdf1_freq.tbl <- function(obj, v, tit) {
pdf1_tbl_freq <- function(obj, var) {
obj %>%
dplyr::count({{ v }}) %>%
dplyr::mutate(`Frequência Relativa` = prop.table(n) %>% round(3)) %>%
dplyr::rename(`Frequência Absoluta` = n) %>%
janitor::adorn_totals("row")
dplyr::count({{ var }}) %>%
dplyr::mutate(`relative_frequency` = prop.table(n) %>% round(3)) %>%
dplyr::rename(`abosulute_frequency` = n) %>%
janitor::adorn_totals("row") |>
dplyr::tibble()
}
26 changes: 13 additions & 13 deletions R/freq-table2.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,43 @@
#'
#' @param obj Object used to create the table. Data frame, list or environment
#' (or object coercible by as.data.frame to a data frame)
#' @param tit Title for the table, write in string format
#' @param v1 Variable that you want the table (not written in string format)
#' @param v2 Variable that you want on the top of the table (not written in string format)
#' @param title titlele for the table, write in string format
#' @param var1 Variable that you want the table (not written in string format)
#' @param var2 Variable that you want on the top of the table (not written in string format)
#' @param ... Other arguments
#' @param marg Marginal row table, default is FALSE

#' @examples
#' mtcars |>
#' mypdf1::pdf1_freq.tbl2(cyl, am, "tit", marg = TRUE)
#' mypdf1::pdf1_tbl_freq2(cyl, am, "title", marg = TRUE)
#' @export
pdf1_freq.tbl2 <- function(obj, v1, v2, tit, marg = F) {
pdf1_tbl_freq2 <- function(obj, var1, var2, title, marg = F) {
tab <- obj %>%
dplyr::group_by({{ v1 }}, {{ v2 }}) %>%
dplyr::group_by({{ var1 }}, {{ var2 }}) %>%
dplyr::summarise(n = dplyr::n()) %>%
tidyr::spread({{ v2 }}, n)
tidyr::spread({{ var2 }}, n)
if (marg != TRUE) {
title2 <- obj |>
dplyr::select({{ v2 }}) |>
dplyr::select({{ var2 }}) |>
names()
catlev <- nrow(unique(obj |>
dplyr::select({{ v2 }}))) + 1
dplyr::select({{ var2 }}))) + 1
tab <- tab |>
janitor::adorn_totals("row") %>%
janitor::adorn_totals("col") %>%
dplyr::ungroup() |>
mypdf1::pdf1_tbl(tit) |>
mypdf1::pdf1_tbl(title) |>
kableExtra::add_header_above(c(" ", setNames(catlev, title2)), align = "c")
} else {
title2 <- obj |>
dplyr::select({{ v2 }}) |>
dplyr::select({{ var2 }}) |>
names()
catlev <- nrow(unique(obj |>
dplyr::select({{ v2 }})))
dplyr::select({{ var2 }})))
tab <- tab |>
janitor::adorn_percentages() %>%
dplyr::ungroup() |>
mypdf1::pdf1_tbl(tit) |>
mypdf1::pdf1_tbl(title) |>
kableExtra::add_header_above(c(" ", setNames(catlev, title2)), align = "c")
}
tab
Expand Down
16 changes: 16 additions & 0 deletions R/imports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' @importFrom janitor untabyl
#' @export
janitor::untabyl

#' @importFrom janitor as_tabyl
#' @export
janitor::as_tabyl









4 changes: 4 additions & 0 deletions R/logo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#library(hexSticker)
#imgurl <- system.file("figures/teste.png", package="mypdf1")
#(sticker(imgurl, package="mypdf1", p_size=20, s_x=1, s_y=.75, s_width=.55,
# h_fill="#E7EDF0", h_color="#135389",p_color = "#135389"))
10 changes: 6 additions & 4 deletions R/pdf1_na.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' this is a very simple table of the quantity of NA by variable
#' this is a very simple table of the quantity of `NA` by variable
#'
#' @param obj Object used to create the table. Data frame, list or environment
#' (or object coercible by as.data.frame to a data frame)
#' @param obj Object used to create the table.
#'
#' `data.frame`, `list` or environment
#' (or object coercible by `as.data.frame` to a `data.frame`)
#' @param ... Other arguments
#' @examples
#' airquality %>%
Expand All @@ -16,5 +18,5 @@ pdf1_na <- function(obj, ...) {
vec <- is.na(obj) |>
as.data.frame() |>
purrr::map_dbl(sum)
dplyr::tibble(`Variavel` = names(vec), `Total_Na` = vec %>% as.vector())
dplyr::tibble(`variable` = names(vec), `total_Na` = vec %>% as.vector())
}
43 changes: 43 additions & 0 deletions R/pdf1_summary.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#' pdf1_summary()
#'
#' this is a very summary generator
#'
#'
#' @param obj Object used to create the table.
#'
#' `data.frame`, `list` or environment
#' (or object coercible by `as.data.frame` to a `data.frame`)
#'
#' @param na_rm option to remove `NA` from variables

#' @examples
#' mtcars |>
#' mypdf1::pdf1_summary()
#'
#' airquality |> mypdf1::pdf1_summary(na_rm = FALSE)
#'
#' iris |> mypdf1::pdf1_summary()
#' @export
pdf1_summary <- function(obj, na_rm = TRUE) {

char <- obj |>
dplyr::select(where((is.character))) |> # dumb i know
ncol()
fac <- obj |>
dplyr::select(where((is.factor))) |> # dumb i know
ncol()
if ((char + fac) != 0) {
warning("string and factors variables were removed for calculations")}
obj <- obj |>
dplyr::select(where(is.numeric))
if( na_rm== TRUE & any(is.na(obj))){
warning("Your dataframe has NA, they will be removed from calculations \n use na_rm = FALSE if you want to keep them")
}


funs <- c(mean = mean, median = median, sd = sd, min = min, max = max)
args <- list(na.rm = na_rm)
obj |>
purrr::map_df(~ funs %>%
purrr::map(purrr::exec, .x, !!!args), .id = "variable")
}
45 changes: 27 additions & 18 deletions R/pdf1_tbl.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
#' pdf1_tbl
#'
#'this is a very simple table generator
#' this is a very simple table generator
#'
#'
#' @param obj Object used to create the table. Data frame, list or environment
#' (or object coercible by as.data.frame to a data frame)
#' @param tit Title for the table, write in string format
#' @param format Format of table, write in string format. Possible values are latex, html.
#' The value of this argument will be automatically determined if the function is called within a knitr document.
#' @param code If you want the table code to appear in the console, put code=TRUE, the default is FALSE, you can combine with format.
#' Remember that by default the format is html
#' @param obj Object used to create the table.
#'
#' `data.frame`, `list` or environment
#' (or object coercible by `as.data.frame` to a `data.frame`)
#' @param title Title for the table, write in string format
#' @param format Format of table, write in string format. Possible values are `"latex"`, "`html`".
#' @param code If you want the table code to appear in the console, put `code=TRUE`, you can combine with `format`.
#' @param ... Other arguments
#' @note Remember that by default the format is `"html"`
#'
#' The default of `code` is `FALSE`
#'
#'The value of `format` will be automatically determined if the function is called within a knitr document
#' @examples
#'iris %>%
#' dplyr::group_by(Species) %>%
#' dplyr::summarise(mean=mean(Sepal.Length)) %>%
#' mypdf1::pdf1_tbl("THIS FUNCTION IS SO INCREDIBLE!")
#' iris %>%
#' dplyr::group_by(Species) %>%
#' dplyr::summarise(mean = mean(Sepal.Length)) %>%
#' mypdf1::pdf1_tbl("THIS FUNCTION IS SO INCREDIBLE!")
#'
#' mtcars |>
#' dplyr::group_by(carb) |>
#' dplyr::summarise(sd = sd(wt)) |>
#' mypdf1::pdf1_tbl()
#' @export
pdf1_tbl=function(obj,tit,format=NULL,code=F,...){
if(code==T){
pdf1_tbl <- function(obj, title = "", format = NULL, code = F, ...) {
if (code == T) {
obj %>%
knitr::kable(caption=tit,align = "c",format=format)
} else{
knitr::kable(caption = title, align = "c", format = format)
} else {
obj %>%
knitr::kable(caption=tit,align = "c",format=format) |>
knitr::kable(caption = title, align = "c", format = format) |>
kableExtra::kable_classic(latex_options = "HOLD_position")

}
}
Loading

0 comments on commit 05f609b

Please sign in to comment.