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

Inaccurate Rd to html conversion for tables with empty cells #645 Issue is persisting #780

Closed
aravind-j opened this Issue Aug 6, 2018 · 7 comments

Comments

Projects
None yet
3 participants
@aravind-j
Copy link

aravind-j commented Aug 6, 2018

After the issue #645 was closed, the error message has disappeared, but the tables are not still as expected,

The empty cells are shifting.

Here are the links to the specific lines for one such table.

Rd - roxygen2
https://github.com/aravind-j/rmelting/blob/c54cede6852bbff36cf3ae8cd5403fbc2292a0e6/man/melting.Rd#L285-L299

html
https://github.com/aravind-j/rmelting/blob/c54cede6852bbff36cf3ae8cd5403fbc2292a0e6/docs/reference/melting.html#L499-L517

pkgdown

Expected
required

@hadley

This comment was marked as outdated.

Copy link
Member

hadley commented Nov 12, 2018

@aravind-j can you please have a go at creating a simpler reprex? There is now advice in https://github.com/r-lib/pkgdown/blob/master/.github/CONTRIBUTING.md#rd-translsation

@hadley hadley added the reprex label Nov 12, 2018

@aravind-j

This comment was marked as outdated.

Copy link
Author

aravind-j commented Nov 18, 2018

With rd2html, I was able to pinpoint the problem. It seems that the problem is because for empty cells, I was using \tab\tab and \tab\cr. When I added a space in between, the html was rendered accurately. R CMD Rd2pdf was ignoring this.

rdstr1 <- c("\\tabular{llll}{ \\strong{Model} \\tab \\strong{Type} \\tab \\strong{Limits.Remarks}\\tab \\strong{Reference} \\cr \\code{sugdna02}* \\tab DNA\\tab Only terminal poly A self \\tab Ohmichi et al., 2002\\cr \\tab\\tab complementary sequences.\\tab \\cr \\code{sugrna02}* \\tab RNA\\tab Only terminal poly A self \\tab Ohmichi et al., 2002\\cr \\tab\\tab complementary sequences.\\tab }")
pkgdown::rd2html(rdstr1)

rdstr1fix <- gsub("\\tab\\tab", "\\tab \\tab", rdstr1, fixed = TRUE)
pkgdown::rd2html(rdstr1fix)


rdstr2 <- c("\\tabular{llll}{ \\strong{Model} \\tab \\strong{Type} \\tab \\strong{Limits/Remarks} \\tab \\strong{Reference} \\cr \\code{sugdna02}* \\tab DNA\\tab Only terminal poly A self\\tab Ohmichi et al., 2002\\cr \\tab\\tab complementary sequences. \\tab\\cr \\code{sugrna02}\\tab RNA\\tab Only terminal poly A self\\tab Ohmichi et al., 2002\\cr \\tab\\tab complementary sequences. \\tab\\cr \\code{ser05} \\tab RNA\\tab Depends on the  available \\tab O'Toole et al., 2005\\cr \\tab\\tab thermodynamic parameters for  \\tab\\cr \\tab\\tab single dangling end. \\tab\\cr \\code{ser06}*\\tab  RNA\\tab\\tab O'Toole et al., 2006 }")
pkgdown::rd2html(rdstr2)

rdstr2fix <- gsub("\\tab\\tab", "\\tab \\tab", rdstr2, fixed = TRUE)
rdstr2fix <- gsub("\\tab\\cr", "\\tab \\cr", rdstr2fix, fixed = TRUE)
pkgdown::rd2html(rdstr2fix)
@hadley

This comment was marked as outdated.

Copy link
Member

hadley commented Nov 19, 2018

Thanks - do you mind having a go at reducing the problem still further? e.g. can you reduce the number of rows and columns, and can you reduce the amount of text inside each cell?

@aravind-j

This comment was marked as outdated.

Copy link
Author

aravind-j commented Nov 19, 2018

I hope this does the job.

rdstr1 <- "\\tabular{lll}{ Alpha \\tab Beta \\tab Gamma \\cr One \\tab Two \\tab Three \\cr A \\tab\\tab C }"
pkgdown::rd2html(rdstr1)

rdstr1fix <- gsub("\\tab\\tab", "\\tab \\tab", rdstr1, fixed = TRUE)
pkgdown::rd2html(rdstr1fix)

rdstr2 <- "\\tabular{lll}{ Alpha \\tab Beta \\tab Gamma \\cr One \\tab Two \\tab\\cr A \\tab B\\tab C }"
pkgdown::rd2html(rdstr1)

rdstr2fix <- gsub("\\tab\\tab", "\\tab \\tab", rdstr2, fixed = TRUE)
rdstr2fix <- gsub("\\tab\\cr", "\\tab \\cr", rdstr2fix, fixed = TRUE)
pkgdown::rd2html(rdstr2fix)
@hadley

This comment was marked as outdated.

Copy link
Member

hadley commented Nov 19, 2018

Perfect, thanks!

@hadley hadley removed the reprex label Nov 19, 2018

@jayhesselberth

This comment was marked as outdated.

Copy link
Collaborator

jayhesselberth commented Nov 19, 2018

Rendered, for reference:

library(pkgdown)

rdstr1 <- "\\tabular{lll}{ Alpha \\tab Beta \\tab Gamma \\cr One \\tab Two \\tab Three \\cr A \\tab\\tab C }"
rd2html(rdstr1)
#> Warning in matrix(cell_contents, ncol = length(align), byrow = TRUE): data
#> length [8] is not a sub-multiple or multiple of the number of rows [3]
#> [1] "<table class='table'>"                             
#> [2] "<tr><td>Alpha</td><td>Beta</td><td>Gamma</td></tr>"
#> [3] "<tr><td>One</td><td>Two</td><td>Three</td></tr>"   
#> [4] "<tr><td>A</td><td>C</td><td>Alpha</td></tr>"       
#> [5] "</table>"

rdstr1fix <- gsub("\\tab\\tab", "\\tab \\tab", rdstr1, fixed = TRUE)
rd2html(rdstr1fix)
#> [1] "<table class='table'>"                             
#> [2] "<tr><td>Alpha</td><td>Beta</td><td>Gamma</td></tr>"
#> [3] "<tr><td>One</td><td>Two</td><td>Three</td></tr>"   
#> [4] "<tr><td>A</td><td></td><td>C</td></tr>"            
#> [5] "</table>"

rdstr2 <- "\\tabular{lll}{ Alpha \\tab Beta \\tab Gamma \\cr One \\tab Two \\tab\\cr A \\tab B\\tab C }"
rd2html(rdstr1)
#> Warning in matrix(cell_contents, ncol = length(align), byrow = TRUE): data
#> length [8] is not a sub-multiple or multiple of the number of rows [3]
#> [1] "<table class='table'>"                             
#> [2] "<tr><td>Alpha</td><td>Beta</td><td>Gamma</td></tr>"
#> [3] "<tr><td>One</td><td>Two</td><td>Three</td></tr>"   
#> [4] "<tr><td>A</td><td>C</td><td>Alpha</td></tr>"       
#> [5] "</table>"

rdstr2fix <- gsub("\\tab\\tab", "\\tab \\tab", rdstr2, fixed = TRUE)
rdstr2fix <- gsub("\\tab\\cr", "\\tab \\cr", rdstr2fix, fixed = TRUE)
rd2html(rdstr2fix)
#> [1] "<table class='table'>"                             
#> [2] "<tr><td>Alpha</td><td>Beta</td><td>Gamma</td></tr>"
#> [3] "<tr><td>One</td><td>Two</td><td></td></tr>"        
#> [4] "<tr><td>A</td><td>B</td><td>C</td></tr>"           
#> [5] "</table>"

Created on 2018-11-19 by the reprex package (v0.2.1)

@hadley hadley added this to the pkgdown 1.2.0 milestone Nov 19, 2018

@hadley

This comment has been minimized.

Copy link
Member

hadley commented Nov 20, 2018

Even more minimal reprex:

library(pkgdown)

x1 <- "\\tabular{lll}{A \\tab B \\tab C \\cr A \\tab\\tab C}"
cat(rd2html(x1), sep = "\n")
#> Warning in matrix(cell_contents, ncol = length(align), byrow = TRUE): data
#> length [5] is not a sub-multiple or multiple of the number of rows [2]
#> <table class='table'>
#> <tr><td>A</td><td>B</td><td>C</td></tr>
#> <tr><td>A</td><td>C</td><td>A</td></tr>
#> </table>

x2 <- "\\tabular{lll}{A \\tab B \\tab\\cr A \\tab B \\tab C}"
cat(rd2html(x2), sep = "\n")
#> Warning in matrix(cell_contents, ncol = length(align), byrow = TRUE): data
#> length [5] is not a sub-multiple or multiple of the number of rows [2]
#> <table class='table'>
#> <tr><td>A</td><td>B</td><td>A</td></tr>
#> <tr><td>B</td><td>C</td><td>A</td></tr>
#> </table>

Created on 2018-11-20 by the reprex package (v0.2.1)

@hadley hadley closed this in e1e6e68 Nov 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment