Skip to content

Commit

Permalink
user-defined indicator for body text in r2md()
Browse files Browse the repository at this point in the history
  • Loading branch information
pzhaonet committed Oct 27, 2018
1 parent 36791d2 commit 555e546
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
12 changes: 7 additions & 5 deletions R/mindr.R
Expand Up @@ -481,7 +481,6 @@ dir2 <- function(path = getwd(),
#' @param filepattern the pattern of the script file names
#' @param savefilename the destinated file name
#' @param backup logical. whether backup the existent file
#' @param heading the indicator of the headings
#' @param body the indicator of the body text
#'
#' @return a markdown file
Expand All @@ -491,8 +490,7 @@ r2md <- function(path = '.',
filepattern = '*.R$',
savefilename = NA,
backup = TRUE,
heading = ' --------$',
body = '^#[^[:blank:]#]+'
body = "#' "
) {
if (dir.exists(path)) {
# read data
Expand All @@ -502,6 +500,7 @@ r2md <- function(path = '.',

# find the indeces of the headings, the body texts, and the code blocks
headerloc <- get_heading(text = rtext)
if(body != '^#[^[:blank:]#]+') body <- paste0('^', body)
bodyloc <- get_body(pattern = body, text = rtext)
codeloc <- grep(pattern = '^[^#]', x = rtext)

Expand All @@ -514,10 +513,13 @@ r2md <- function(path = '.',

# process the headings
## remove the heading marker
rtext[headerloc] <- gsub(pattern = heading, '', rtext[headerloc])
rtext[headerloc] <- gsub(pattern = '[#-]{4,}$', '', rtext[headerloc])

# process the body text
rtext[bodyloc] <- gsub(pattern = '^#', '', rtext[bodyloc])
bodypattern <- ifelse(body == '^#[^[:blank:]#]+',
'^#',
paste0('^', body))
rtext[bodyloc] <- gsub(pattern = bodypattern, '', rtext[bodyloc])

# write
foldername <- get_foldername(path)
Expand Down
5 changes: 1 addition & 4 deletions man/r2md.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 555e546

Please sign in to comment.