Skip to content

Commit

Permalink
Version 0.2
Browse files Browse the repository at this point in the history
Two new functions
  • Loading branch information
AlissonRP authored Jan 8, 2022
2 parents e3d9b3e + 64fd5d0 commit d7630e2
Show file tree
Hide file tree
Showing 26 changed files with 290 additions and 191 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.github$
6 changes: 6 additions & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
inst/doc
*.html
40 changes: 40 additions & 0 deletions .github/workflows/check-release.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
30 changes: 30 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

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: covr

- name: Test coverage
run: covr::codecov()
shell: Rscript {0}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
.Rhistory
.RData
.Ruserdata
inst/doc
11 changes: 9 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mypdf1
Type: Package
Title: Rmarkdown template
Version: 0.1.4
Version: 0.2
Author: Alisson Rosa
Depends: R (>= 4.1.0)
Maintainer: The package maintainer <alirperera887@gmail.com>
Expand All @@ -14,4 +14,11 @@ Imports:
dplyr,
ggplot2,
kableExtra,
magrittr
purrr,
magrittr,
stats,
janitor,
lifecycle
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

export("%>%")
export(pdf1_freq.tbl)
export(pdf1_freq.tbl2)
export(pdf1_na)
export(pdf1_tbl)
export(untabyl)
importFrom(magrittr,"%>%")
125 changes: 0 additions & 125 deletions R/adorn_totals.R

This file was deleted.

1 change: 0 additions & 1 deletion R/as_tabyl.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ as_tabyl <- function(dat, axes = 2, row_var_name = NULL, col_var_name = NULL) {
#' tabyl(am) %>%
#' untabyl() %>%
#' attributes() # tabyl-specific attributes are gone

untabyl <- function(dat) {
if (is.list(dat) && !is.data.frame(dat)) {
purrr::map(dat, untabyl)
Expand Down
7 changes: 7 additions & 0 deletions R/autoset.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
auto_set_format <- function() {
if (knitr::is_latex_output()) {
options(knitr.table.format = "latex")
} else {
options(knitr.table.format = "html")
}
}
20 changes: 10 additions & 10 deletions R/freq-table.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' pdf1_freq.tbl
#'
#'this is a very simple frequency table generator
#' this is a very simple frequency table generator
#'
#'
#' @param obj Object used to create the table. Data frame, list or environment
Expand All @@ -9,14 +9,14 @@
#' @param v 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(" You can combine this function too!")
#' iris %>%
#' mypdf1::pdf1_freq.tbl(Species, "title") %>%
#' mypdf1::pdf1_tbl(" You can combine this function too!")
#' @export
pdf1_freq.tbl=function(df,v,tit){
df %>%
dplyr::count({{v}}) %>%
dplyr::mutate(`Frequência Relativa`=prop.table(n) %>% round(3)) %>%
dplyr::rename(`Frequência Absoluta`=n) %>%
mypdf1:::adorn_totals("row")
pdf1_freq.tbl <- function(obj, v, tit) {
obj %>%
dplyr::count({{ v }}) %>%
dplyr::mutate(`Frequência Relativa` = prop.table(n) %>% round(3)) %>%
dplyr::rename(`Frequência Absoluta` = n) %>%
janitor::adorn_totals("row")
}
49 changes: 49 additions & 0 deletions R/freq-table2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#' pdf1_freq.tbl
#'
#' @description
#' `r lifecycle::badge("experimental")`
#' #'this is a very simple frequency 2x2 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 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 ... Other arguments
#' @param marg Marginal row table, default is FALSE

#' @examples
#' mtcars |>
#' mypdf1::pdf1_freq.tbl2(cyl, am, "tit", marg = TRUE)
#' @export
pdf1_freq.tbl2 <- function(obj, v1, v2, tit, marg = F) {
tab <- obj %>%
dplyr::group_by({{ v1 }}, {{ v2 }}) %>%
dplyr::summarise(n = dplyr::n()) %>%
tidyr::spread({{ v2 }}, n)
if (marg != TRUE) {
title2 <- obj |>
dplyr::select({{ v2 }}) |>
names()
catlev <- nrow(unique(obj |>
dplyr::select({{ v2 }}))) + 1
tab <- tab |>
janitor::adorn_totals("row") %>%
janitor::adorn_totals("col") %>%
dplyr::ungroup() |>
mypdf1::pdf1_tbl(tit) |>
kableExtra::add_header_above(c(" ", setNames(catlev, title2)), align = "c")
} else {
title2 <- obj |>
dplyr::select({{ v2 }}) |>
names()
catlev <- nrow(unique(obj |>
dplyr::select({{ v2 }})))
tab <- tab |>
janitor::adorn_percentages() %>%
dplyr::ungroup() |>
mypdf1::pdf1_tbl(tit) |>
kableExtra::add_header_above(c(" ", setNames(catlev, title2)), align = "c")
}
tab
}
19 changes: 19 additions & 0 deletions R/pdf1_na.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' pdf1_na
#'
#' @description
#' `r lifecycle::badge("experimental")`
#' 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 ... Other arguments
#' @examples
#' airquality %>%
#' mypdf1::pdf1_na()
#' @export
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())
}
Loading

0 comments on commit d7630e2

Please sign in to comment.