Skip to content

Commit

Permalink
New function for building book part and current part open in editor !
Browse files Browse the repository at this point in the history
  • Loading branch information
plecharpent committed Oct 12, 2020
1 parent b09d5fa commit 9e29e76
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
39 changes: 39 additions & 0 deletions R/generate_book.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,42 @@ get_output_dir <- function(dir = getwd()) {

gsub(pattern = "output_dir: (.*)", x = l[idx], replacement = "\\1")
}



build_book_part <- function( file_name = NULL, other_names = c("index", "Appendices")){

# For a single file name
if (is.null(file_name)) {
in_doc <- get_active_doc()
} else {
in_doc <- file_name
}

if(length(file_name) > 1) stop("Only one file name is required")

if (!grepl(pattern = "\\.Rmd$", x = in_doc)) stop("Not a Rmd file")

if( !file.exists(in_doc)) stop("File does not exist!")

# check if this is a bookdown part
book_dir <- dirname(in_doc)
print(book_dir)
if(!file.exists(file.path(book_dir, "index.Rmd"))) stop("Not a bookdown part")

# Getting appendices and references parts
other_files <- unlist(lapply(other_names , function(x) grep(pattern = x, x = list.files(book_dir, pattern = "\\.Rmd$"), value = TRUE)))


# Adding extra parts
if(length(other_files)) in_doc <- c(in_doc, other_files)


generate_book(input_rmd = unique(in_doc))

}


build_current_book_part <- function() {
build_book_part()
}
5 changes: 5 additions & 0 deletions inst/rstudio/addins.dcf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ Name: Find and insert Stics names
Description: Searching names based on partial match, insert formatted name for RMarkdown.
Binding: find_stics_names
Interactive: true

Name: Build current book part
Description: Buidling a bookdown part open in editor ...
Binding: build_current_book_part
Interactive: false

0 comments on commit 9e29e76

Please sign in to comment.