ggplot images not appearing in .md github_documents

Viewed 26

I recently parameterized hundreds of reports. The html_documents look great, but in the .md reports, which are github_documents, the images are not appearing.

.md file viewed in GitHub: enter image description here

Same .md file in raw format: enter image description here

The images have successfully pushed to GitHub: enter image description here

Why aren't my image files mapping to my reports?

1 Answers

The problem lay in how I specified the location of my output files in the render() function within my for loop.

This loop specified absolute file paths and in turn the image file locations were also being specified with absolute file paths.

dir_datasets <- here::here('data', 'cooked', 'gamma_a4_b0-04')

mdes <- c(.980, .990, .995, 1.010, 1.020, 1.030)
mdes_str <- broman::myround(mdes, 3)
my_files <- list.files(dir_datasets)

for (mde in mdes) {
    for (file in my_files){
        TRUE_EFFECT <- extract_string_from_filename(file, 3)
        MDE_TITLE <- dash4dot(mde, 3)

        rmarkdown::render(
            fs::path(dir_sprt_ttest, 'template.Rmd'),
            output_file = fs::path(
                dir_output, paste0('tte', TRUE_EFFECT, '_mde', MDE_TITLE, '.md')
                ),
            params = list(file_name = file, mde = mde)
        )
    }
}

When I remove the absolute filepath from the output_file argument in render() the images were thereafter saved with relative filepaths, too, and the .md files displayed their images after being pushed to GitHub.

output_file = paste0('tte', TRUE_EFFECT, '_mde', MDE_TITLE, '.md') # note that I dropped fs::path(dir_output,
Related