poissonconsulting / subreport

An R package to knit tables, figures, numbers etc saved using subfoldr2
https://poissonconsulting.github.io/subreport/
Other
1 stars 0 forks source link

Stripping heading at same level even when a higher level heading occurs between #19

Open joethorley opened 1 year ago

joethorley commented 1 year ago

Heading 1 A

Heading X

Heading A

Heading X <- THIS IS BEING DROPPED ERRONEOUSLY

sebdalgarno commented 1 year ago

narrowed it down to internal set_headings function and more specifically

> str(heading)
 chr [1:2, 1:2] "Count" "Count2" "Species" "Species"
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:2] "sub1" "sub2"
> 

being passed to

  heading <- apply(heading, MARGIN = 2, new_only)

with new_only, the second column of heading gets converted to c("Species", NA) since they are duplicated

> heading
     sub1     sub2     
[1,] "Count"  "Species"
[2,] "Count2" "Species"

to

> heading
     sub1     sub2     
[1,] "Count"  "Species"
[2,] "Count2" NA  

NA is dropped when collapsed and this becomes

heading
[1] "\n#### Count\n\n##### Species\n" "\n#### Count2\n"                
> 
sebdalgarno commented 1 year ago

is the new_only step necessary? @joethorley do you remember the cases that it is trying to address?

sebdalgarno commented 1 year ago

or do we want to work on the rows instead? i.e.

  heading <- apply(heading, MARGIN = 1, subreport:::new_only)

gives

> heading
[1] "\n#### Count\n\n#### Species\n"    "\n##### Count2\n\n##### Species\n"
> 
joethorley commented 1 year ago

It's a good question. We only want to drop a subheading if it and all its higher level headings are the same. Currently it just ask is it the same at the same level.

joethorley commented 1 year ago

So yes we want new_only but it needs to be more nuanced.