rmdcount: Word, character and non-whitespace characters count

Description Usage Arguments Details Value Examples

View source: R/rmdcount.R

Description

Counts words, characters and non-whitespace characters in R Markdown files.

Usage

1
rmdcount(files = NULL, space = "[[:space:]]", word = "[[:space:]]+")

Arguments

files

character: file name(s)

space

character: pattern to split a text at spaces (default: '[[:space:]]')

word

character: pattern to split a text at word boundaries (default: '[[:space:]]+')

Details

It uses the following approaches to detect words, characters and non-whitespace characters.

words

strsplit(rmd, word)[[1]] with word equal to '[[:space:]]+'

characters

strsplit(rmd, '')[[1]]

non-whitespace characters

strsplit(gsub(space, '', rmd), '')[[1]] with space equal to '[[:space:]]'

This is repeated for the text without code chunks. Code chunks are deleted with gsub('```\\{.*?```', '', rmd).

Value

a data frame wthe following elements

file

basename of a file

words

number of words including code chunks

chars

number of characters including code chunks

nonws

number of non-whitespace characters including code chunks

words_chunk

number of words excluding code chunks

chars_chunk

number of characters excluding code chunks

nonws_chunk

number of non-whitespace characters excluding code chunks

path

path of a file

Examples

1
2
3
4
5
6
files <- system.file('rmarkdown/rstudio_pdf.Rmd', package="rmdwc")
rmdcount(files)
# use of rmdcount() in a R Markdown document 
if (interactive()) {
  file.edit(files) # SAVE(!) the file and knit it 
}

rmdwc documentation built on Aug. 27, 2020, 5:08 p.m.