Skip to content

Changing name of git-tracked Rmd file breaks get_session_info() #1

Description

@gadenbuie

If I've understood correctly, when running get_session_info() inside an Rmd that is being rendered, the following lines in try to determine the directory containing the source document.

if (my_current_input_w_dir != 'No Input File Detected') {
all_git_files <- system('git ls-files -co --no-empty-directory --full-name', intern = TRUE)
folder_info_in <- dirname(all_git_files[unlist(lapply(all_git_files, function(xx) grepl(xx, my_current_input_w_dir)))])
} else {

If you're rendering a document that is tracked by git but has not been checked in or committed, then after this section folder_info_in will be zero-length because the modified source document won't be listed.

To reproduce this, rename vignettes/moffittfunctions.Rmd to vignettes/MoffittFunctions.Rmd and render.

> rmarkdown::render("vignettes/MoffittFunctions.Rmd")
# ...

Browse[2]> my_current_input_w_dir
[1] "/Users/4468739/work/external/MoffittFunctions/vignettes/MoffittFunctions.Rmd"
Browse[2]> all_git_files
[1] "vignettes/moffittfunctions.Rmd" "vignettes/moffittfunctions.tex"
Browse[2]> folder_info_in
character(0)
Browse[2]> c
Quitting from lines 505-515 (MoffittFunctions.Rmd) 
Error in data.frame(name = "location", value = folder_info_in, stringsAsFactors = FALSE) : 
  arguments imply differing number of rows: 1, 0

I'm not full certain what output is desired from folder_info, but one strategy would be to add a custom string if (!length(folder_info_in)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions