Rapporter / pander

An R Pandoc Writer: Convert arbitrary R objects into markdown
http://rapporter.github.io/pander/
Open Software License 3.0
294 stars 66 forks source link

floats and tables on same page #288

Closed HJAllen closed 7 years ago

HJAllen commented 7 years ago

I am having a problem when floating figures and tables are on the same page. This issue has been identified elsewhere but haven't found a solution. https://github.com/yihui/knitr/issues/863 The code chunk looks like this (not a functioning example)

```{r example1}
cat.ptr <- function(df, Digits = 3, Caption = NULL, Justify='left',
                    Style='rmarkdown', Split.table=Inf, Split.cells = Inf,
                    Tag = NULL, font.s = '\\footnotesize\n\n')
{
  #test for POSIX class columns in df so non-breaking hyphens can be inserted
  date.test <- grepl('POSIX',lapply(df,class))
  if(any(date.test))df[,date.test] <- format(df[,date.test], format = '%Y\\-%m\\-%d', tz = tz(df[,date.test]))
  cat(font.s)
  cat(pandoc.table.return(df,
                          digits = Digits,
                          caption = paste(Caption, Tag),
                          justify = Justify,
                          style = Style,
                          split.table = Split.table,
                          split.cells = Split.cells
                          ),
      "\n\n", sep='')
  cat('\\normalsize\n\n')
}

cat.pir <- function(plot.g, Caption = NULL, Tag = NULL)
{
  cat(pandoc.image.return(plot.g, caption = Caption),
      Tag,
      "\n\n", sep='')
  cat("\\FloatBarrier","\n\n")
}

assay <- 'MC_ADDA_20150615A'
#dataF <- e.dat[e.dat$AssayID == assay,]
x <- e.out[[assay]]

plate.abs.eval<-evals('print(x$assay.p)')
#using pandoc.image.return to set entry for image and caption and cross reference
cat.pir(plot.g = plate.abs.eval[[1]]$result,
        Caption = paste0(assay," well map."),
        Tag = paste0("{#fig:wellMap",assay,"}"))

#output standards table
row.names(x$standards$dataF) <- NULL
row.names(x$standards$dataF.s) <- NULL
row.names(x$standards$dataF.s.drm2) <- NULL

cat.ptr(df = x$standards$dataF[x$standards$dataF$Type == 'Standard', colnames(x$standards$dataF) %in% c('ShortID','Row','Column','Replicate','Absorbance')],
        Caption = paste0('Standards absorbance for assay ', assay, '.'),
        Tag = paste0('{#tbl:standards', assay, '}'))

#output standards QA table
row.names(x$standards$dataF.s) <- NULL
cat.ptr(df = x$standards$dataF.s[,colnames(x$standards$dataF.s) %in% c('ShortID','N','meanAbs','sdAbs','cvAbs','cvFlagAbs')],
        Caption = paste0('Standards summary for assay ', assay, '.'),
        Tag = paste0('{#tbl:standardsQA', assay, '}'))

#output standards table
cat.ptr(df = x$standards$dataF[,colnames(x$standards$dataF) %in% c('ShortID','Row','Column','Replicate','Absorbance')],
        Caption = paste0('Standards absorbance including pooled zero standard for assay ', assay, '.'),
        Tag = paste0('{#tbl:standardspooled', assay, '}'))

#output standards QA table
row.names(x$standards$dataF.s) <- NULL
cat.ptr(df = x$standards$dataF.s.drm2[,colnames(x$standards$dataF.s.drm2) %in% c('ShortID','N','meanAbs','sdAbs','cvAbs','cvFlagAbs')],
        Caption = paste0('Standards summary for assay ', assay, '.'),
        Tag = paste0('{#tbl:standardsQApooled', assay, '}'))

#output standard curve by first calling evals to create plot
#then pandoc.image.return to get markdown formated entry
stand.grid <- grid.arrange(x$standards$curves$drm1$stnds.g, x$standards$curves$drm2$stnds.g, ncol=2)
stand.curve.drm1<-evals('plot(stand.grid)')
#using pandoc.image.return to set entry for image and caption and cross reference
cat.pir(plot.g = stand.curve.drm1[[1]]$result,
        Caption=paste0('Standard curve: ', assay, '.'),
        Tag = paste0('{#fig:stand.curve.drm1', assay, '}'))


The subsequent pdf page looks like:

![image](https://cloud.githubusercontent.com/assets/6650920/23074758/f6ea3478-f507-11e6-8e14-3847722baf15.png)
HJAllen commented 7 years ago

After some more digging I found https://groups.google.com/forum/#!topic/pandoc-discuss/pWsApQDpp9A which discussed using a longtable-patched.sty file. I implemented this which took care of the problem.