Skip to content

Commit

Permalink
Merge branch 'iss-52-title'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbcann01 committed Feb 15, 2024
2 parents cb30872 + d45cf93 commit fb7f164
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: codebookr
Title: Create Codebooks from Data Frames
Version: 0.1.7
Version: 0.1.8
Authors@R: person("Brad", "Cannell", email = "[email protected]",
role = c("aut", "cre", "cph"))
Maintainer: Brad Cannell <[email protected]>
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# codebookr 0.1.8

* Fix issue where the word "Codebook" that was previously printed at the top of the codebook document printed at the bottom of the codebook document. Additionally, if there was a title or subtitle, that was printed at the bottom of the codebook as well.

# codebookr 0.1.7

* Fix dplyr warning, "Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
Expand Down
2 changes: 1 addition & 1 deletion R/codebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ codebook <- function(
# ===========================================================================
# Optionally add title and subtitle to top of codebook
# ===========================================================================
cb_shell <- cb_add_title(
rdocx <- cb_add_title(
rdocx = rdocx,
title = title,
subtitle = subtitle
Expand Down
4 changes: 3 additions & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ There were 2 NOTEs
1. We encountered this note on Windows Server 2022, R-devel, 64 bit running `devtools::check_rhub()`.

checking for non-standard things in the check directory ... NOTE
Found the following files/directories:
''NULL''

There is no file name given. We aren't sure what this note is referrring to. Therefore, no action was taken.
There is no file name given. We aren't sure what this note is referring to. Therefore, no action was taken.

2. We encountered this note on Windows Server 2022, R-devel, 64 bit running `devtools::check_rhub()`.

Expand Down
Binary file added test.docx
Binary file not shown.
28 changes: 28 additions & 0 deletions tests/testthat/test-codebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,31 @@ testthat::test_that("The check for a data frame works as expected", {
df <- data.frame(x = letters, y = 1:26)
testthat::expect_message(df %>% codebook(), "The codebook function currently sees the name of the data frame you passed to the `df` argument as '.'. This is probably because you used a pipe to pass the data frame name into the codebook function. If you want the actual name of the data frame to be printed in the `Dataset name:` row of the metadata table, do not use a pipe to pass the data frame name into the codebook function.")
})

# In response to issue #52, test to make sure that the word "Codebook" is printed at the top of the document
testthat::test_that("The word 'Codebook' is printed at the top of the Word document", {
# Create a test codebook.
cb <- codebook(
df = study,
title = "My Example Study",
subtitle = "A Subtitle for My Example Study Codebook",
description = "Test description"
)

# Create a Word codebook as a tempfile
cb_doc <- print(cb, tempfile(fileext = ".docx"))

# Check for the word "Codebook" at the top of the file
# Helpful website: http://cran.nexr.com/web/packages/officer/vignettes/officer_reader.html
doc <- officer::read_docx(cb_doc)
content <- officer::docx_summary(doc)
paragraphs <- subset(content, content_type %in% "paragraph")

# Run the test
testthat::expect_true(paragraphs$text[1] == "Codebook")

# Also test that for the title, subtitle, and description
testthat::expect_true(paragraphs$text[2] == "My Example Study")
testthat::expect_true(paragraphs$text[3] == "A Subtitle for My Example Study Codebook")
testthat::expect_true(paragraphs$text[8] == "Test description")
})

0 comments on commit fb7f164

Please sign in to comment.