| 1 |
\name{read.org.table} |
| 2 |
\title{Read.table for an Emacs Org Table} |
| 3 |
\alias{read.org.table} |
| 4 |
\description{ |
| 5 |
Read an emacs \dQuote{Org} table (in \code{file} or \code{text}) by |
| 6 |
\code{\link{read.table}()}. % FIXME: Should be easy to made to work for some of the |
| 7 |
%% Markdown formats for tables. |
| 8 |
} |
| 9 |
\usage{ |
| 10 |
read.org.table(file, header = TRUE, skip = 0, |
| 11 |
encoding = "native", fileEncoding = "", text, quiet=FALSE, \dots) |
| 12 |
} |
| 13 |
\arguments{ |
| 14 |
\item{file}{a file name, a \code{\link{file}} or other connection.} |
| 15 |
\item{header}{logical indicating if the org table has header line (in |
| 16 |
the usual \code{"|"}-separated org table format).} |
| 17 |
\item{skip}{integer number of initial lines to skip.} |
| 18 |
\item{encoding}{to be used in the main |
| 19 |
\code{\link{readLines}(file, encoding=encoding)} call.} |
| 20 |
\item{fileEncoding}{if \code{file} is a file name, i.e., a |
| 21 |
\code{\link{character}} string, and \code{fileEncoding} is not the |
| 22 |
empty string, \code{file(file, "rt", encoding = fileEncoding)} will |
| 23 |
be used.} |
| 24 |
\item{text}{instead of \code{file}, a \code{\link{character}} or |
| 25 |
string (of a few lines, typically).} |
| 26 |
\item{quiet}{\code{\link{logical}} to suppress the \code{\link{message}} |
| 27 |
which is signalled when no \code{nrows=*} has been specified and the |
| 28 |
automatic number of rows is smaller than 95\% of the rows / non-header |
| 29 |
lines of the \code{file}.} |
| 30 |
\item{\dots}{further arguments passed to \code{\link{read.table}}. |
| 31 |
You should \emph{not} use \code{encoding} (but possibly |
| 32 |
\code{fileEncoding}!) here, as we do not call |
| 33 |
\code{\link{read.table}} on \code{file} (but on a |
| 34 |
\code{\link{textConnection}}).} |
| 35 |
} |
| 36 |
\value{ |
| 37 |
a \code{\link{data.frame}} |
| 38 |
} |
| 39 |
\note{TODO: It should be easy to extend \code{read.org.table()} to also |
| 40 |
work for some of the proposed Markdown formats for tables. |
| 41 |
Please write to \code{\link{maintainer}("sfsmisc")} or open a |
| 42 |
github issue if you are interested. |
| 43 |
} |
| 44 |
\references{ |
| 45 |
Org-Mode \emph{Manual} on tables, \url{https://orgmode.org/manual/Tables.html} |
| 46 |
|
| 47 |
Org \emph{tutorial} for tables, \url{https://orgmode.org/worg/org-tutorials/tables.html} |
| 48 |
} |
| 49 |
\seealso{ |
| 50 |
CRAN package \CRANpkg{ascii} % \CRANpkg{ascii} % <- needs R >= 3.2.0 |
| 51 |
can \emph{write} org tables. |
| 52 |
\code{\link{read.table}} |
| 53 |
} |
| 54 |
\examples{ |
| 55 |
t1 <- |
| 56 |
" |
| 57 |
| a | var2 | C | |
| 58 |
|---+------+-----| |
| 59 |
| 2 | may | 3.4 | |
| 60 |
| 7 | feb | 4.7 | |
| 61 |
" |
| 62 |
d <- read.org.table(text = t1) |
| 63 |
d |
| 64 |
stopifnot(dim(d) == c(2, 3), |
| 65 |
identical(names(d), c("a", "var2", "C")), |
| 66 |
d[,"a"] == c(2,7)) |
| 67 |
%% TODO: 2nd example similar with a *closing* "|----+......|" line !!! |
| 68 |
} |
| 69 |
\keyword{file} |
| 70 |
\keyword{utilities} |