Search code examples
rpdfexport-to-pdf

Is it possible to export a large R table into a PDF file?


I need to export a table I made in r from binding different values enter image description here

I've tried with library(gridExtra) but it's not working (perhaphs I'm using it wrong)

FA=table(ant$municipionombre)
View(FA)
prop.table(table(ant$municipionombre))


#Percentage Relative Frequency/Frecuencia relativa porcentual
FR=FA/margin.table(FA)
View(FR)


#Cumulative Absolute Frequency/Frecuencia absoluta acumulada
FAA=cumsum(FA)
View(FAA)

#Cumulative Percentage Relative Frequency/Frecuencia relativa porcentual acumulada
FRP=cumsum(FA)/margin.table(FA)
View(FRP)

#Percentage by entry
perc=FR*100
perc

#Build a table with all variables (FA, FAA, FR, FRP, perc)
tab1=cbind(FA,FAA,FR,FRP,perc)
tab1
View(tab1)```


Solution

  • I don't really understand your code above, as you haven't provided useable sample data. But the fundamental question of how to export data to a PDF can be accomplished with the reporter package.

    There are three steps:

    1. Create the table content.
    2. Create a report.
    3. Write out the report.

    Here is an example using the iris data frame.

    
    library(reporter)
    
    
    tbl <- create_table(iris) %>% 
      titles("My PDF Report")
    
    rpt <- create_report("c:\\temp\\test.pdf", output_type = "PDF") %>% 
      add_content(tbl)
    
    
    write_report(rpt)
    

    Here is a portion of the PDF:

    enter image description here