knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) options(rmarkdown.html_vignette.check_title = FALSE)
Below are some frequently asked questions about the reporter package. Click on the links below to navigate to the full question and answer content.
Q: I can see from the examples that the reporter package can create text reports. Can it create any other types of reports? PDF? DOCX?
A: The reporter package supports TXT, RTF, PDF, HTML, and DOCX output types.
Q: I see a lot of Courier font in the examples. Does reporter support any other fonts?
A: The supported fonts depend on the output type selected. Obviously for
TXT reports, no fonts are supported.
The RTF, PDF, HTML, and DOCX output types support Courier, Arial, Times New Roman,
and SimSun. SimSun is a font specifically for Chinese characters.
Note that the "Courier" font keyword actually produces "Courier New" on the output report.
Q: The examples show little in the way of styling: fonts, colors, bolding, etc. What options are there for adding styles to the report?
A: Styles and themes are now available for the HTML output type. Take a look at the styles vignette for more information about this exciting new feature.
For all other output types, the titles() function has parameters to bold the title
block, and set the font size independently of the main report. Styling such
as that for HTML will
become available for other output types in the near future.
You may also add styling via code insertion. See the vignette Example 17: Code Insertion for an illustration.
Q: All of the examples I saw show a landscape page orientation. Is there a way to have a portrait page orientation?
A: Yes. The orientation parameter on the create_report() function
accepts both "landscape" and "portrait" values.
Q: All of the examples I saw show column widths specified in inches. Is there a way to specify them in metric? What about by percentage?
A: The units parameter on the create_report() function allows you
to control the units of measure. Valid values are "inches" and "cm" for
centimeters. The parameter accepts no other value. The issue of setting
column widths by percentage has been raised, and is under consideration as
a future enhancement.
Note that this parameter sets the units of measure for every measurement
on the report, not just column widths. The units for margins, table width,
plot width, etc. will all be understood to be in the units specified on the
units parameter. In other words, the whole report will be in either inches
or centimeters. You cannot mix measurement systems on a report.
Q: With SASĀ® proc report, I can add statistics to my report. Does the reporter package have any statistical capabilities?
A: No. The focus of the reporter package is on creating a printable report in multiple output types. There are many R packages to generate statistics. If you want statistics in your report, run your desired statistical functions, and add the result to the input data.
Q: With SASĀ® proc report, I can group my data in the reporting procedure. Does the reporter package have grouping capabilities?
A: No. There are already several ways to group data in R. It is best
to group data with one of the existing functions before sending into the
reporter package. Note that group rows can be emphasized on the
report using the dedupe, blank_after, and label_row parameters on
the define() function.
See example 2 and example 3
from the vignettes for a demonstration
on how to use these parameters.
Q: I have some data to report on, but it is not sorted the way I want for reporting. Does reporter have any way to sort the data?
A: No. There are many ways to sort data in R. It is therefore recommended to sort the data before sending it into the reporter package.
Generally speaking, the input data should be fully prepared for reporting. The reporter package will take your input data pretty much as-is and create a report in the desired output file format. Any data manipulation should be done prior to reporting.
Q: I have some data to report on, but it is not filtered the way I want. Does reporter have any way to filter the data?
A: No. There are many ways to filter data in R. It is therefore recommended to filter the data before sending it into the reporter package.
Q: I want to add some superscripts and subscripts to my report. Does reporter have a way to do that?
A: Yes. The reporting functions recognize Unicode superscript and subscript characters. These characters may be entered as a 4-digit Unicode code. For instance, the code "\U00B2" specifies a superscript two. See the superscript and subscript vignette for further explanation on this topic.
Q: I have some data to report on, but it has more columns than I want to show in the report. Does reporter have any way to remove some columns from the report?
A: Yes. There are two ways to remove a column from the report. The first
is to use the show_cols parameter on the create_table() function. This
parameter accepts a vector of column names to include on the table.
The second way is to use the visible parameter on the define() function.
Setting this parameter to FALSE will hide that variable on the report.
Q: The variables in my data are not ordered exactly as I want them to appear on the report. Is there a way to control column order?
A: Generally it is better to prepare your input data so that everything
is ordered the way you want prior to reporting. But there is a way
to order the columns if they are not in the desired order. You can use
the show_cols parameter on the create_table() function to do this.
Simply pass a vector of column names to the show_cols parameter, and put
the column names in the order you want them to appear on the report.
Note that if you are using define() functions, the order of these functions
have no affect on the order of columns on the report.
Q: I have variable in my input data that is not formatted. I want to apply a format to it; say, round to 1 decimal place and add a percent sign. Is there a way to format a variable?
A: Yes. You can use the format parameter on the define()
function to identify a format for a variable. The format passed to this
parameter should be a valid format for the
fapply() function from the
fmtr package.
See the fapply()
documentation for additional information.
Q: Overall, the reporter package does a good job of determining when to break to the next page. However, sometimes I want to control exactly when the page break occurs. Is there a way to do that?
A: Yes. You can add a variable to your input data that has the desired
page number for each row. Then use the page_break parameter on the define()
function to identify that variable as a page break variable. The package
will then use that variable to break pages, instead of the automatic
paging variable.
Note that, by default, reporter will still break
the page if the number of rows on a page exceeds the calculated line count. If
you want to disable the automatic paging, and have 100% control
over when page breaks occur, turn automatic page breaking off using
report_option(auto_page = FALSE).
You can also control the line count on a page using the line_count
parameter on the options_fixed() or report_options functions.
For a full explanation of the page breaking options, See the vignette Example 18: Report Options.
Q: Overall, the reporter package does a good job of determining when to wrap a page when it is too wide. However, sometimes I want to control exactly when the page wrap occurs. Is there a way to do that?
A: Yes. You can use the page_wrap parameter on the define()
function to identify a variable to wrap on. See Example 6: Page Wrap
in the documentation for an illustration of how to wrap pages.
You can also turn the automatic
page wrapping off completely with report_options(page_wrap = FALSE) or create_table(page_wrap = FALSE). See Example 18: Report Options for more
information.
Q: I see there are several ways to set column widths. However, I just want to set the width of the entire table, and have reporter figure out the column widths proportionally. Is there a way to do that?
A: Yes. You can use the width parameter on the create_table()
function to set a width for the entire table. The width should be specified
in the units identified on the units parameter on the create_report()
function. See the create_table() function documentation for more information
on the width parameter.
Q: I'm trying to use curly braces in my footnotes. For some reason, I keep getting an error. Why?
A: The curly braces are delimiter characters for the glue function, which is automatically run on titles, footnotes, and labels. You can use the curly braces to reference a variable or run a function from within string. To avoid the error, you can escape the glue functionality by doubling the curly braces. In other words, use "{{mystring}}" instead of "{mystring}".
If you're inserting
code into your report with report_options(allow_code = TRUE), please also
double the curly braces if needed. See Example 17: Code Insertion
You can also turn off the glue functionality globally by setting
options("reporter.glue" = FALSE).
Q: I have some very long words in my data. I want reporter to break them, and wrap to the next line. Is there a way to do that?
A: No. The reporter package will not break words.
What you should do is pre-process the column with the long words,
and break it yourself. You can use the nchar() function to check the character
length of the words. Then insert a new line or blank space at the point where
you want to break. Once the words are broken where you want, send the data
into reporter.
Q: I'm trying to insert some RTF codes into my report, but they always come out visible on the output. Is there a way to insert them directly into the RTF, without reporter interfering?
A: Yes. reporter normally prevents such code insertion. But you
can allow it by setting report_options(allow_code = TRUE). The "allow_code"
option will work for RTF and HTML. See the vignette
Example 17: Code Insertion for an example.
Q: I'm trying to create some reports with reporter on a Mac, but they seem to be consistently messed up. RTF is really messed up and DOCX doesn't come out right either. How can I fix it?
A: The reporter package was developed on Windows, and tested on Linux. Those two platforms are supported best. On a Mac, TXT and PDF output types should be reliable. As for RTF and DOCX, they will work or not depending on which editor you are using. RTF and DOCX are best interpreted on Microsoft Word for Mac. For HTML, the content produced will be correct, but usually the page breaking is off. The reason is because Safari has different defaults and different interpretations of some HTML tags and styles. You can improve the HTML output by viewing on Chrome for Mac.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.