Browse Source

Fix CRAN check issues on Fedora

master
boB Rudis 4 years ago
parent
commit
29a6818a3d
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 17
      DESCRIPTION
  2. 3
      NEWS.md
  3. 95
      inst/tinytest/test_docxtractr.R
  4. 4
      tests/testthat.R
  5. 11
      tests/testthat/test-doc-conversion.R
  6. 54
      tests/testthat/test-docxtractr.R
  7. 23
      tests/testthat/test-pptx-conversion.R
  8. 5
      tests/tinytest.R

17
DESCRIPTION

@ -1,6 +1,6 @@
Package: docxtractr
Title: Extract Data Tables and Comments from 'Microsoft' 'Word' Documents
Version: 0.6.2
Version: 0.6.5
Authors@R: c(
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5670-2640")),
@ -14,18 +14,19 @@ Description: 'Microsoft Word' 'docx' files provide an 'XML' structure that is fa
comments. Tools are provided to determine table count/structure, comment count
and also to extract/clean tables and comments from 'Microsoft Word' 'docx' documents.
There is also nascent support for '.doc' files.
SystemRequirements: LibreOffice (<https://www.libreoffice.org/>) required to extract
data from .doc files.
SystemRequirements: LibreOffice
(<https://www.libreoffice.org/>) required to extract
data from .doc files or perform .pptx conversion.
URL: http://gitlab.com/hrbrmstr/docxtractr
BugReports: https://gitlab.com/hrbrmstr/docxtractr/issues
Encoding: UTF-8
Depends:
R (>= 3.2.0)
Depends:
R (>= 3.6.0)
License: MIT + file LICENSE
LazyData: true
Suggests:
testthat,
covr
Suggests:
covr,
tinytest
Imports:
tools,
xml2,

3
NEWS.md

@ -14,8 +14,7 @@
# 0.4.0
- add a `preserve` logical paramater to tbl extraction functions to support preserving
intra-cell whitespace (implements #9)
- add a `preserve` logical paramater to tbl extraction functions to support preserving intra-cell whitespace (implements #9)
- use `httr` vs `download.file()` for URL retrieval (fixes #10)
# 0.3.0 WIP

95
inst/tinytest/test_docxtractr.R

@ -0,0 +1,95 @@
library(docxtractr)
doc <- read_docx(system.file("examples/data.docx", package="docxtractr"))
suppressMessages(x <- capture.output(print(doc)))
x <- capture.output(docx_describe_tbls(doc))
suppressMessages(expect_equal(length(docx_extract_all(doc)), 1))
expect_equal(length(docx_extract_all_tbls(doc)), 1)
expect_true(inherits(doc, "docx"))
expect_equal(docx_tbl_count(doc), 1)
expect_true(inherits(docx_extract_tbl(doc, 1), "tbl"))
complx <- read_docx(system.file("examples/complex.docx", package="docxtractr"))
expect_equal(docx_tbl_count(complx) ,5)
tmp_3 <- docx_extract_tbl(complx, 3)
tmp_4 <- docx_extract_tbl(complx, 4)
tmp_5 <- docx_extract_tbl(complx, 5)
expect_true(inherits(tmp_3, "tbl"))
expect_true(inherits(tmp_4, "tbl"))
expect_true(inherits(tmp_5, "tbl"))
expect_equal(nrow(tmp_3), 6)
expect_equal(ncol(tmp_4), 3)
expect_equal(nrow(tmp_5), 6)
tmp_6 <- assign_colnames(tmp_5, 1)
expect_equal(colnames(tmp_6), c("Aa", "Bb", "Cc"))
cmnt <- read_docx(system.file("examples/comments.docx", package="docxtractr"))
expect_equal(docx_cmnt_count(cmnt), 3)
x <- capture.output(docx_describe_cmnts(cmnt))
suppressMessages(x <- capture.output(print(cmnt)))
expect_equal(nrow(docx_extract_all_cmnts(cmnt)), 3)
real_world <- read_docx(system.file("examples/realworld.docx", package="docxtractr"))
tbls <- docx_extract_all_tbls(real_world)
expect_equal(
colnames(mcga(assign_colnames(tbls[[1]], 2))),
c("country", "birthrate", "death_rate", "population_growth_2005",
"population_growth_2050", "relative_place_in_transition", "social_factors_1",
"social_factors_2", "social_factors_3")
)
# docx-conversion ---------------------------------------------------------
if (at_home()) {
lp = try({
docxtractr:::lo_find()
}, silent = TRUE)
if (!inherits(lp, "try-error")) {
path <- system.file("examples/preserve.doc", package = "docxtractr")
doc = read_docx(path)
expect_that(doc, is_a("docx"))
}
}
# pptx conversion ---------------------------------------------------------
if (at_home()) {
lp = try({
docxtractr:::lo_find()
}, silent = TRUE)
if (!inherits(lp, "try-error")) {
path <- system.file("examples/ex.pptx", package = "docxtractr")
pdf <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
expect_true(file.size(pdf) > 0)
}
}
if (at_home()) {
lp = try({
docxtractr:::lo_find()
}, silent = TRUE)
if (!inherits(lp, "try-error")) {
path <- system.file("examples/data.docx", package = "docxtractr")
pdf <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
expect_true(file.size(pdf) > 0)
}
}

4
tests/testthat.R

@ -1,4 +0,0 @@
library(testthat)
library(docxtractr)
test_check("docxtractr")

11
tests/testthat/test-doc-conversion.R

@ -1,11 +0,0 @@
context("DOC conversion works")
test_that("we can convert a DOC to DOCX if LibreOffice Installed", {
lp = try({
docxtractr:::lo_find()
}, silent = TRUE)
if (!inherits(lp, "try-error")) {
path <- system.file("examples/preserve.doc", package = "docxtractr")
doc = read_docx(path)
expect_that(doc, is_a("docx"))
}
})

54
tests/testthat/test-docxtractr.R

@ -1,54 +0,0 @@
context("docx extraction works")
test_that("we can do something", {
doc <- read_docx(system.file("examples/data.docx", package="docxtractr"))
x <- capture.output(print(doc))
x <- capture.output(docx_describe_tbls(doc))
expect_equal(length(docx_extract_all(doc)), 1)
expect_equal(length(docx_extract_all_tbls(doc)), 1)
expect_that(doc, is_a("docx"))
expect_that(docx_tbl_count(doc), equals(1))
expect_that(docx_extract_tbl(doc, 1), is_a("tbl"))
complx <- read_docx(system.file("examples/complex.docx", package="docxtractr"))
expect_that(docx_tbl_count(complx), equals(5))
tmp_3 <- docx_extract_tbl(complx, 3)
tmp_4 <- docx_extract_tbl(complx, 4)
tmp_5 <- docx_extract_tbl(complx, 5)
expect_that(tmp_3, is_a("tbl"))
expect_that(tmp_4, is_a("tbl"))
expect_that(tmp_5, is_a("tbl"))
expect_that(nrow(tmp_3), equals(6))
expect_that(ncol(tmp_4), equals(3))
expect_that(nrow(tmp_5), equals(6))
tmp_6 <- assign_colnames(tmp_5, 1)
expect_equal(colnames(tmp_6), c("Aa", "Bb", "Cc"))
cmnt <- read_docx(system.file("examples/comments.docx", package="docxtractr"))
expect_equal(docx_cmnt_count(cmnt), 3)
x <- capture.output(docx_describe_cmnts(cmnt))
x <- capture.output(print(cmnt))
expect_equal(nrow(docx_extract_all_cmnts(cmnt)), 3)
real_world <- read_docx(system.file("examples/realworld.docx", package="docxtractr"))
tbls <- docx_extract_all_tbls(real_world)
expect_equal(colnames(mcga(assign_colnames(tbls[[1]], 2))),
c("country", "birthrate", "death_rate", "population_growth_2005",
"population_growth_2050", "relative_place_in_transition", "social_factors_1",
"social_factors_2", "social_factors_3"))
})

23
tests/testthat/test-pptx-conversion.R

@ -1,23 +0,0 @@
context("PPTX conversion works")
test_that("we can convert a PPTX if LibreOffice Installed", {
lp = try({
docxtractr:::lo_find()
}, silent = TRUE)
if (!inherits(lp, "try-error")) {
path <- system.file("examples/ex.pptx", package = "docxtractr")
pdf <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
expect_true(file.size(pdf) > 0)
}
})
test_that("we can convert a DOCX to PDF if LibreOffice Installed", {
lp = try({
docxtractr:::lo_find()
}, silent = TRUE)
if (!inherits(lp, "try-error")) {
path <- system.file("examples/data.docx", package = "docxtractr")
pdf <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
expect_true(file.size(pdf) > 0)
}
})

5
tests/tinytest.R

@ -0,0 +1,5 @@
if ( requireNamespace("tinytest", quietly=TRUE) ){
tinytest::test_package("docxtractr")
}
Loading…
Cancel
Save