process: Process an R Markdown file

Description Usage Arguments Details Value See Also

View source: R/process.R

Description

Process an R Markdown file to generate a CALIBER codelist together with documentation. The text can have extension .Rmd or .txt (which may be more convenient on Windows). If it is a R file (extension .R) or a CALIBERcodelists log file (.log), it is processed as a R script instead. The categories and metadata are always cleared at the start of this function.

The working directory is assumed to be the directory containing the Markdown file; the new HTML file and codelists are created in this directory (although codelists can be exported elsewhere if the directory is specified in the export or exportall function.

Usage

1
2
process(filename, varname = NULL, showR = FALSE, 
    showhtml = TRUE, show_not_selected = TRUE, css = customCSS())

Arguments

filename

the name of the R markdown file or R script to process (if it is in the current working directory), or the full filepath if it is elsewhere. If the file extension is .R or .log, it is assumed to be an R script, otherwise it is assumed to be a R Markdown document.

varname

the variable name. This can be left blank if it is supplied in the Rmd document in a line containing text such as "Name|angina" to set varname to be "angina".

showR

whether to show the R output by default, if no output options are specified for a Markdown chunk.

showhtml

whether to automatically call showhtml at the end of document to show the final codelist.

show_not_selected

whether to show terms with the same three-character code (and more than 100 events for GPRD terms) but not included in the exported codelist. Ignored if showhtml = FALSE.

css

custom stylesheet for HTML documentation. For convenience the default option is hard-coded into the internal customCSS function, which can be viewed using CALIBERcodelists:::customCSS

Details

The search strategy and documentation for a set of codelists for a CALIBER variable can be documented in R Markdown. Markdown is a plain text format with simple ways of denoting headings, bullet points and tables, which enables R code to be embedded directly within the document. process uses the knitr package to run the R code and embed the results in the HTML document.

The table of codelist metadata should be entered like this (it doesn't matter if the | do not line up):

1
2
3
4
5
6
Name    | mycodelist 
--------|--- 
Author  | Anoop Shah 
Version | 2 
Date    | 1 Jan 2013 
Changes | Corrected term XXX to category 3.

In the HTML document, this is automatically formatted like this:

Name mycodelist
Author Anoop Shah
Version 2
Date 1 Jan 2013
Changes Corrected term XXX to category 3.

The ‘Changes’ field is not enforced by the program, and is not necessary for the first version of a codelist.

The codelist name will be taken from the metadata table, and used as the stem for files exported using exportall (i.e. the GPRD codelist file will be named mycodelist_gprd.codelist.2.csv).

R code is entered like this:

1
2
3
4
5
6
```{r}
# Enter R code here, e.g.
setdictionary('read', 'icd10')
assigncat(1, 'hcm', termhas('hypertroph*cardiomyopath'))
exportall()
```

R code with HTML output can be entered like this (to produce a table of the current codelists selected in the master dictionary):

1
2
3
```{r results='asis'}
showhtml()
```

This is automatically included at the end of the document (if showhtml = TRUE), but to put the table of terms at a different point in the document call process with showhtml = FALSE and explicitly enter a showhtml command.

Value

A string describing the comparison between the current codelists and the previously saved version of the codelists (if available), also stored in META['message', value]

See Also

as.codelist, assigncat, export, exportall, getdictionary, setdictionary, showhtml


CALIBERcodelists documentation built on Feb. 28, 2020, 3:01 a.m.