Skip to content

Commit

Permalink
Merge pull request #11 from AlissonRP/templates
Browse files Browse the repository at this point in the history
version 0.5
  • Loading branch information
AlissonRP authored Apr 13, 2022
2 parents ee928fa + 1a6d71a commit a253237
Show file tree
Hide file tree
Showing 32 changed files with 168 additions and 74 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.github$
^codecov\.yml$
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Description: Rmarkdown template for writing pdf reports using Latex syntax (PT-B
License: GPL
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
Imports:
dplyr,
ggplot2,
Expand All @@ -18,8 +18,10 @@ Imports:
magrittr,
stats,
janitor,
lifecycle
lifecycle,
tidyr
Suggests:
covr,
testthat (>= 3.0.0)
Config/testthat/edition: 3
Roxygen: list(markdown = TRUE)
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

export("%>%")
export(as_tabyl)
export(pdf1_freq.tbl)
export(pdf1_na)
export(pdf1_summary)
export(pdf1_tbl)
Expand Down
7 changes: 0 additions & 7 deletions R/autoset.R

This file was deleted.

13 changes: 0 additions & 13 deletions R/freq-table-DE.R

This file was deleted.

1 change: 0 additions & 1 deletion R/freq-table.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#' @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 var Variable that you want the table (not written in string format)
#' @param ... Other arguments
#' @examples
#' iris %>%
#' mypdf1::pdf1_tbl_freq(Species) %>%
Expand Down
17 changes: 11 additions & 6 deletions R/freq-table2.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@
#'
#' @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 titlele for the table, write in string format
#' @param title title 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_tbl_freq2(cyl, am, "title", marg = TRUE)
#' @export
pdf1_tbl_freq2 <- function(obj, var1, var2, title = '', marg = F) {
tab <- obj %>%
dplyr::group_by({{ var1 }}, {{ var2 }}) %>%
dplyr::summarise(n = dplyr::n()) %>%
tidyr::spread({{ var2 }}, n)
if(any(is.na(obj |> dplyr::select({{var1}},{{var2}}))) == TRUE){
warning('Your dataframe has NA, they will be removed from calculations')
}
tab <- obj |>
tab({{ var1}}, {{var2}})
tab[is.na(tab)] = 0
if (marg != TRUE) {
title2 <- obj |>
dplyr::select({{ var2 }}) |>
Expand All @@ -49,3 +50,7 @@ pdf1_tbl_freq2 <- function(obj, var1, var2, title = '', marg = F) {
}
tab
}




2 changes: 1 addition & 1 deletion R/imports.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ janitor::as_tabyl




utils::globalVariables(c("where", "median", "sd", "n", "setNames"))



4 changes: 2 additions & 2 deletions R/pdf1_na.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#' @description
#' `r lifecycle::badge("experimental")`
#'
#' this is a very simple table of the quantity of `NA` by variable
#' this is a very simple table generator of the quantity of `NA` by variable
#'
#' @param obj Object used to create the table.
#' @param obj Object used to create the table.
#'
#' `data.frame`, `list` or environment
#' (or object coercible by `as.data.frame` to a `data.frame`)
Expand Down
2 changes: 1 addition & 1 deletion R/pdf1_summary.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' pdf1_summary()
#'
#' this is a very summary generator
#' this is a very simple summary generator
#'
#'
#' @param obj Object used to create the table.
Expand Down
6 changes: 3 additions & 3 deletions R/pdf1_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
#' dplyr::summarise(sd = sd(wt)) |>
#' mypdf1::pdf1_tbl()
#' @export
pdf1_tbl <- function(obj, title = "", format = NULL, code = F, format.p.val = F,...) {
pdf1_tbl <- function(obj, title = "", format = NULL, code = F,...) {
if (code == T) {
obj %>%
knitr::kable(caption = title, align = "c", format = format)
kableExtra::kable(caption = title, align = "c", format = format)
} else {
obj %>%
knitr::kable(caption = title, align = "c", format = format) |>
kableExtra::kable(caption = title, align = "c", format = format) |>
kableExtra::kable_classic(latex_options = "HOLD_position")
}
}
9 changes: 9 additions & 0 deletions R/tab.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tab = function(obj, var1, var2) {
obj %>%
dplyr::group_by({{ var1 }}, {{ var2 }}) %>%
dplyr::summarise(n = dplyr::n()) %>%
tidyr::spread({{ var2 }}, n)

}


15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# mypdf1 <img src='figures\mypdf1.png' align="right" height="130" /></a>
# mypdf1 <img src='man/figures/fig/mypdf1.png' align="right" height="130" /></a>

[![R build
status](https://github.com/tidyverse/dplyr/workflows/R-CMD-check/badge.svg)](https://github.com/AlissonRP/mypdf1/actions/workflows/check-release.yaml)
status](https://github.com/tidyverse/ggplot2/workflows/R-CMD-check/badge.svg)](https://github.com/AlissonRP/mypdf1/actions)
[![Codecov
test coverage](https://codecov.io/gh/AlissonRP/mypdf1/branch/main/graph/badge.svg)](https://app.codecov.io/gh/AlissonRP/mypdf1?branch=main)



Expand All @@ -16,9 +18,14 @@ So this package provides a template for pdf reports in Rmarkdown and quite usual
```r
devtools::install_github("https://github.com/AlissonRP/mypdf1")
```
## Use of template
## Use of default template
```r
rmarkdown::draft("namefile.Rmd", template = "pdf1", package = "mypdf1", create_dir = FALSE)
rmarkdown::draft("namefile.Rmd", template = "pdf1", package = "mypdf1")
```
## Use of paper template

```r
rmarkdown::draft("namefile.Rmd", template = "pdf1 - paper", package = "mypdf1", create_dir = FALSE)
```

## Some functions already available
Expand Down
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
comment: false

coverage:
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
9 changes: 3 additions & 6 deletions inst/rmarkdown/templates/pdf1/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ abstract: "abstract"
header-includes:
- \usepackage[brazil]{babel}
- \usepackage{bm}
- \usepackage{float}
geometry: left=1.7cm, right=1.7cm, top=3cm, bottom=3cm
output:
bookdown::pdf_document2:
editor_options:
chunk_output_type: console
indent: true
bibliography: bib.bib
csl: statistics.csl
nocite: '@*'
link-citations: true
---


Expand All @@ -24,7 +21,7 @@ link-citations: true
options(digits=3) #Arrendodamento
options(scipen=999)
ggplot2::theme_set(ggplot2::theme_minimal()) #Tema dos gráficos produzidos no ggplot2
knitr::opts_chunk$set(echo=F,message=F,warning=F,fig.pos = 'H',fig.align = 'center',fig.width=7.8, fig.height=4.85)
knitr::opts_chunk$set(echo=F,message=F,warning=F,fig.pos = 'H',fig.align = 'center',fig.width=6, fig.height=4.0)
scale_fill_discrete = \(...) ggplot2::scale_fill_brewer(... , palette="Set2") #Fixa a scale do fill dos gráficos do ggplot2
```
Expand All @@ -40,7 +37,7 @@ iris |>
```{r crftable}
iris |>
mypdf1::pdf1_freq.tbl(Species,"seila") |>
mypdf1::pdf1_tbl_freq(Species,"seila") |>
mypdf1::pdf1_tbl("You can combine this function too!")
```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\newpage
66 changes: 66 additions & 0 deletions inst/rmarkdown/templates/pdf1_paper/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: "title"
author: "author"
abstract: "abstract"
header-includes:
- \usepackage[brazil]{babel}
- \usepackage{bm}
- \usepackage{float}
geometry: left=1.7cm, right=1.7cm, top=3cm, bottom=3cm
output:
bookdown::pdf_document2:
includes:
before_body: beforebody.tex
editor_options:
chunk_output_type: console
indent: true
toc: True
bibliography: bib.bib
csl: style.csl
nocite: '@*'
link-citations: true
---

\clearpage
\tableofcontents

```{r setup,include=F}
options(digits=3) #Arrendodamento
options(scipen=999)
ggplot2::theme_set(ggplot2::theme_minimal()) #Tema dos gráficos produzidos no ggplot2
knitr::opts_chunk$set(echo=F,message=F,warning=F,fig.pos = 'H',fig.align = 'center',fig.width=7.8, fig.height=4)
scale_fill_discrete = \(...) ggplot2::scale_fill_brewer(... , palette="Set2") #Fixa a scale do fill dos gráficos do ggplot2
```


\section{Section name}
```{r }
#R code
iris |>
mypdf1::pdf1_summary()
```
```{r crftable}
iris |>
mypdf1::pdf1_tbl_freq(Species) |>
mypdf1::pdf1_tbl("You can combine this function too!")
```
You cross-reference tables like this: Table \@ref(tab:crftable)

```{r crfgraph, fig.cap = "fig name"}
plot(rnorm(500))
```

You cross-reference figures like this: Figure \@ref(fig:crfgraph)


# Bibliography

```{r}
```

4 changes: 4 additions & 0 deletions inst/rmarkdown/templates/pdf1_paper/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: pdf1-paper
description: >
Rmarkdown template for writing pdf reports using Latex syntax.
create_dir: false
File renamed without changes.
File renamed without changes
File renamed without changes
19 changes: 0 additions & 19 deletions man/pdf1_freq.tbl.Rd

This file was deleted.

2 changes: 1 addition & 1 deletion man/pdf1_na.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/pdf1_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/pdf1_tbl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions man/pdf1_tbl_freq.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/pdf1_tbl_freq2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed mypdf1.png
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/testthat/test-frequency.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ test_that("sum total", {
mypdf1::pdf1_tbl_freq(Species) |> (\(x) x[4, 2])() |> as.numeric(), 150)
expect_equal(iris %>%
mypdf1::pdf1_tbl_freq(Species) |> (\(x) x[4, 3])() |> round(2) |> as.numeric(), 1)
expect_warning(
airquality |>
mypdf1::pdf1_tbl_freq2(Ozone, Month),'Your dataframe has NA, they will be removed from calculations'
)
})

Loading

0 comments on commit a253237

Please sign in to comment.