liftr
                                
                                
                                
                                    liftr copied to clipboard
                            
                            
                            
                        Extract package names from Rmd source and write to configuration file
Possibly using the source parse tree offered by lintr by @jimhester .
https://cran.r-project.org/web/packages/lintr/vignettes/creating_linters.html
or try this one (also applies to require(), ::, etc.):
sub(".*library\\(\"(.*?)\"\\).*", "\\1", grep("library\\(", readLines("foo.Rmd"), value = TRUE))
                                    
                                    
                                    
                                
Maybe an R function + an RStudio addin for this purpose using the above snippet.
Note to self: packrat:::fileDependencies and packrat:::fileDependencies.Rmd should be the right way to go.