Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix table rowspan downward fill bug #216

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions R/table.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ html_table.xml_node <- function(x, header = NA, trim = TRUE,
l <- utils::head(out[j+k, ], i-1)
r <- utils::tail(out[j+k, ], maxp-i+1)
out[j + k, ] <- utils::head(c(l, out[j, i], r), maxp)
nrows[[j+k]] <- c(1, nrows[[j+k]])
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,23 @@ test_that("a correct but slightly pathological table correctly parsed", {
c(rep('Categorical Columns', 2),
rep('Numerical Columns', 2)))
})

test_that("Test Wiki table correctly parsed", {
table <- read_html("../testwiki.html") %>%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please replace these with the simplest possible inline data? Relying on an external website makes for fragile tests.

html_nodes('.wikitable') %>% html_table(fill = TRUE)

row92 <- c('Burdur', 'Ahmet Ali Çınar', 'NA', 'Bağımsız')
row138 <- c('Denizli', 'Cemil Çalgüner', 'NA', 'Cumhuriyet Halk Partisi')
expect_equal(as.character(table[[1]][92,]), row92)
expect_equal(as.character(table[[1]][138,]), row138)

})

test_that("Test Wiki more difficult table correctly parsed", {
table <- read_html("https://tr.wikipedia.org/wiki/TBMM_12._d%C3%B6nem_milletvekilleri_listesi") %>%
html_nodes('.wikitable') %>% html_table(fill = TRUE)

row7 <- c('Adana', 'Ahmet Topaloğlu', 'NA', 'Adalet Partisi')
expect_equal(as.character(table[[1]][7,]), row7)
})

Loading