Skip to content

Commit

Permalink
test with default table style in latex
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Apr 29, 2024
1 parent 63008f9 commit b026605
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 268 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ ignore/*
^codecov\.yml$
^dev$
^README\.html$
^inst/examples/data\.qmd$
^inst/examples/text\.qmd$
16 changes: 14 additions & 2 deletions R/extract_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ extract_metadata <- function(file, password = NULL, copy = FALSE) {
on.exit(pdfDocument$close())

info <- pdfDocument$getDocumentInformation()

info_creation_date <- info$getCreationDate()
info_modification_date <- info$getModificationDate()

if (!is.null(info_creation_date)) {
info_creation_date <- info_creation_date$getTime()$toString()
}

if (!is.null(info_modification_date)) {
info_modification_date <- info_modification_date$getTime()$toString()
}

list(
pages = pdfDocument$getNumberOfPages(),
title = info$getTitle(),
Expand All @@ -31,8 +43,8 @@ extract_metadata <- function(file, password = NULL, copy = FALSE) {
keywords = info$getKeywords(),
creator = info$getCreator(),
producer = info$getProducer(),
created = info$getCreationDate()$getTime()$toString(),
modified = info$getModificationDate()$getTime()$toString(),
created = info_creation_date,
modified = info_modification_date,
trapped = info$getTrapped()
)
}
2 changes: 1 addition & 1 deletion R/output.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ list_characters <- function(tables, delim = "\t", encoding = NULL, ...) {
list_data_frames <- function(tables, delim = "\t", encoding = NULL, ...) {
char <- list_characters(tables = tables, delim = delim, encoding = encoding)
lapply(char, function(x) {
o <- try(read_delim(file = x, delim = delim))
o <- try(read_delim(file = x, delim = delim, show_col_types = FALSE))
if (inherits(o, "try-error")) {
return(x)
} else {
Expand Down
33 changes: 0 additions & 33 deletions inst/examples/data.Rnw

This file was deleted.

Binary file modified inst/examples/data.pdf
Binary file not shown.
33 changes: 33 additions & 0 deletions inst/examples/data.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
format: pdf
---

\pagenumbering{gobble}

```{r, echo=FALSE}
library(xtable)
library(datasets)
options(xtable.comment = FALSE)
```

```{r, results="asis", echo=FALSE}
print(xtable(mtcars, align = "|l|r|r|r|r|r|r|r|r|r|r|r|"), include.rownames = FALSE)
```

\clearpage

```{r, results="asis", echo=FALSE}
print(xtable(head(iris), align = "|l|r|r|r|r|r|"), include.rownames = FALSE)
```

\vspace{20em}

```{r, results="asis", echo=FALSE}
print(xtable(tail(iris), align = "|l|r|r|r|r|r|"), include.rownames = FALSE)
```

\clearpage

```{r, results="asis", echo=FALSE}
print(xtable(ToothGrowth[1:15, ], align = "|l|r|r|r|"), include.rownames = FALSE)
```
219 changes: 0 additions & 219 deletions inst/examples/data.tex

This file was deleted.

16 changes: 8 additions & 8 deletions tests/testthat/test_extract_tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ test_that("Warning for ignored arguments", {
test_that("Test 'guess' argument", {
tab1a <- extract_tables(sf, pages = 1, guess = TRUE)
tab1b <- extract_tables(sf, pages = 1, guess = FALSE)
expect_true(ncol(tab1a[[1]]) == 10)
expect_true(ncol(tab1b[[1]]) == 13)
expect_true(ncol(tab1a[[1]]) == 11)
expect_true(ncol(tab1b[[1]]) == 11)

tab2a <- extract_tables(sf, pages = 2, guess = TRUE)
tab2b <- extract_tables(sf, pages = 2, guess = FALSE)
expect_true(length(tab2a) == 2)
expect_true(length(tab2a) == 1)
expect_true(length(tab2b) == 1)
})

Expand All @@ -46,22 +46,22 @@ test_that("Test 'area' argument", {
tab4a <- extract_tables(sf, pages = 1, area = a4a, guess = FALSE, output = "tibble")
expect_true(is.list(tab4a))
expect_true(is.data.frame(tab4a[[1]]))
expect_true(nrow(tab4a[[1]]) == 32)
expect_true(ncol(tab4a[[1]]) == 12)
expect_true(nrow(tab4a[[1]]) == 28)
expect_true(ncol(tab4a[[1]]) == 10)
a4b <- list(c(122, 149, 251, 464))
tab4b <- extract_tables(sf, pages = 1, area = a4b, guess = FALSE, output = "tibble")
expect_true(is.list(tab4b))
expect_true(is.data.frame(tab4b[[1]]))
expect_true(nrow(tab4b[[1]]) == 9)
expect_true(ncol(tab4b[[1]]) == 8)
expect_true(nrow(tab4b[[1]]) == 8)
expect_true(ncol(tab4b[[1]]) == 9)
})

test_that("Test 'columns' argument", {
tab5 <- extract_tables(sf, pages = 1, columns = list(c(0, 612)), guess = FALSE)
expect_true(is.list(tab5))
expect_true(length(tab5) == 1)
expect_true(ncol(tab5[[1]]) == 2)
expect_true(nrow(tab5[[1]]) == 33)
expect_true(nrow(tab5[[1]]) == 32)
})

test_that("Extract from encrypted PDF", {
Expand Down
Loading

0 comments on commit b026605

Please sign in to comment.