check_pdf: Check the PDF file

Description Usage Arguments Details Value Author(s) Examples

View source: R/utils.R

Description

This function checks that the PDF file does not exist to avoid overwriting a plot the user has previously made.

Usage

1
check_pdf(PDF = "four_panels.pdf", OUTDIR = tempdir())

Arguments

PDF

The name of the PDF file. Defaults to four_panels.pdf.

OUTDIR

The default directory where PDF will be saved to.

Details

This is an utility function used by four_panels and plot_coverage.

Value

The path to the PDF file if the file doesn't exist. It appends the pdf file extension if it was absent from PDF.

Author(s)

Leonardo Collado-Torres

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Choose a random PDF file
PDF <- paste0("test_", stats::runif(1, max = 1e10))

## Initially this works because the output PDF does not exist.
PDF <- check_pdf(PDF)
## It also adds the PDF extension if the user didn't supply it.
PDF

## Create a dummy PDF file
pdf(file = PDF)
plot(1, 1)
dev.off()

## Now it doesn't work since the PDF file already exists.
testthat::expect_error(
    check_pdf(basename(PDF)),
    "already exists! Rename or erase it"
)

brainflowprobes documentation built on Dec. 21, 2020, 2:01 a.m.