Skip to content
This repository has been archived by the owner on Mar 23, 2020. It is now read-only.

Commit

Permalink
new function text_extract
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgohel committed Feb 3, 2015
1 parent accb9d8 commit 377be1e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export(textBoldItalic)
export(textItalic)
export(textNormal)
export(textProperties)
export(text_extract)
export(toc.options)
export(triggerPostCommand)
export(vanilla.table)
Expand Down
32 changes: 32 additions & 0 deletions R/text_extract.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' @title Simple Text Extraction From a Word Document
#'
#' @description
#' Provides a simple method to get text from a docx document.
#' It returns a \code{character} vector containing all
#' chunk of text found in the document.
#' @param x \code{\link{docx}} object
#' @param body specifies to scan document body
#' @param header specifies to scan document header
#' @param footer specifies to scan document footer
#' @param bookmark a character value ; id of the Word bookmark to scan.
#' @return a character vector
#' @examples
#' #START_TAG_TEST
#' doc = docx( title = "My example", template = file.path(
#' find.package("ReporteRs"), "templates/bookmark_example.docx") )
#' text_extract( doc )
#' text_extract( doc, header = FALSE, footer = FALSE )
#' text_extract( doc, bookmark = "author" )
#' @example examples/STOP_TAG_TEST.R
#' @seealso \code{\link{docx}}
#' @export
text_extract = function( x, body = TRUE, header = TRUE, footer = TRUE, bookmark){
if( missing( bookmark ) )
out = .jcall(x$obj, "[S", "getWords", body, header, footer)
else {
if( length( bookmark ) != 1 || !is.character(bookmark))
stop("bookmark must be an atomic character.")
out = .jcall(x$obj, "[S", "getWords", casefold( bookmark, upper = FALSE ) )
}
out
}
Binary file modified inst/java/ReporteRs-0.7.jar
Binary file not shown.
Binary file modified java/ReporteRs-0.7-src.jar
Binary file not shown.
40 changes: 40 additions & 0 deletions man/text_extract.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/text_extract.R
\name{text_extract}
\alias{text_extract}
\title{Simple text extraction from a docx document}
\usage{
text_extract(x, body = TRUE, header = TRUE, footer = TRUE, bookmark)
}
\arguments{
\item{x}{\code{\link{docx}} object}

\item{body}{specifies to scan document body}

\item{header}{specifies to scan document header}

\item{footer}{specifies to scan document footer}

\item{bookmark}{a character value ; id of the Word bookmark to scan.}
}
\value{
a character vector
}
\description{
Provides a simple method to get text from a docx document.
It returns a \code{character} vector containing all
chunk of text found in the document.
}
\examples{
#START_TAG_TEST
doc = docx( title = "My example", template = file.path(
find.package("ReporteRs"), "templates/bookmark_example.docx") )
text_extract( doc )
text_extract( doc, header = FALSE, footer = FALSE )
text_extract( doc, bookmark = "author" )
#STOP_TAG_TEST
}
\seealso{
\code{\link{docx}}
}

0 comments on commit 377be1e

Please sign in to comment.