Re: [Rd] declaring package dependencies

2013-09-13 Thread Gray Calhoun

John Fox: (12:15PM on Fri, Sep 13)
[...cut...]

I think that most users --
as opposed to R developers -- will find the package::function( ... ) syntax
in examples not so much ugly as cryptic. I think that we have ample recent
evidence on this list that even developers (I don't exempt myself) are
confused by namespace issues. On balance, I prefer

if (require(MASS)) {
loglm( ...)
}

which tells the user that it's necessary to load MASS before using loglm().

It would be nice if examples ran in a sandbox, so that an example could
read something like

library(MASS)
loglm( ... )
. . .

without affecting the path in the current session, and fail gracefully if
the MASS package weren't available (unlikely, of course, in the case of
MASS, but not more generally).


Does assigning

loglm - MASS::loglm
loglm( ... )

not work in examples anymore? (with MASS listed under 'Suggests'.)
That seems like it could address both concerns, but it would mask
loglm if it were already defined.

--
Gray Calhoun, Assistant Professor of Economics at Iowa State 
http://gray.clhn.co // (515) 294-6271 // 467 Heady Hall


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Problem with question about \preformatted in .Rd

2011-11-26 Thread Gray Calhoun
I need to correct one minor typo below:

On Fri, Nov 25, 2011 at 6:12 PM, Gray Calhoun gray.calh...@gmail.com wrote:
(cut a lot)
  I expected from the documentation to get this:

 \inputencoding{utf8}
 \HeaderA{test}{test}{test}
 %
 \begin{Section}{problems}
 \begin{alltt}print('\bsl{}\bsl{}\bsl{}\begin\bsl{}\bsl{}\{block\bsl{}\bsl{}\}')\end{alltt}
 \end{Section}

The second to last line should read:
\begin{alltt}print('\bsl{}\bsl{}\bsl{}\bsl{}begin\bsl{}\bsl{}\{block\bsl{}\bsl{}\}')\end{alltt}
Sorry about that.

--Gray


-- 
Gray Calhoun

Assistant Professor of Economics, Iowa State University
http://www.econ.iastate.edu/~gcalhoun

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Problem with question about \preformatted in .Rd

2011-11-25 Thread Gray Calhoun
Hi,

The \preformatted environment in Rd files doesn't seem to escape
long sequences of backslashes properly when converted to pdf (LaTeX)
documentation.  I'm running R version 2.14 (from subversion, revision
57751) on Linux (RHEL).  Here's an example from the command line:

echo 
\title{test}\name{test}\section{problems}{\preformatted{print('begin\{block\}')}}
 temp.Rd
R CMD Rdconv --type=latex temp.Rd

which outputs:

\inputencoding{utf8}
\HeaderA{test}{test}{test}
%
\begin{Section}{problems}
\begin{alltt}print('begin\\{block\\}')\end{alltt}
\end{Section}

and the double backslashes become newlines when this text is embedded
in a complete document and converted to pdf.  I expected from the
documentation to get this:

\inputencoding{utf8}
\HeaderA{test}{test}{test}
%
\begin{Section}{problems}
\begin{alltt}print('\bsl{}\bsl{}\bsl{}\begin\bsl{}\bsl{}\{block\bsl{}\bsl{}\}')\end{alltt}
\end{Section}

The problem seems to come from tools:::Rd2latex as this R code indicates:

library(tools)
tools:::Rd2latex(textConnection(\\title{test}\\name{test}
\\section{problems}{
\\preformatted{
print('begin\\{block\\}')
}}))

(the output is the same as from the command line above)

I can get the behavior that I want by removing a few lines from the
relevant part of tools:::Rd2latex and I provide a patch below, but I
assume that the code that I removed was put there for a good reason so
this isn't a good fix.  make check-devel didn't find any errors,
though.

I'm happy to fill out a bug report for this if that's the next appropriate step.

A question: why is there special code to handle \var inside
\preformatted environments?  The documentation reads:

\preformatted{text}
Indicate text that is a literal example of a piece of a program.
Text is displayed using typewriter font if possible. Formatting, e.g.
line breaks, is preserved.

Due to limitations in LaTeX as of this writing, this macro may not
be nested within other markup macros other than \dQuote and \sQuote,
as errors or bad formatting may result.

which doesn't indicate that \var should be handled any differently
than any other macro, but the code makes me think that R is trying to
pass the macro through to LaTeX.

Thanks!

--Gray

-- 
Gray Calhoun

Assistant Professor of Economics, Iowa State University
http://www.econ.iastate.edu/~gcalhoun

patch:

Index: src/library/tools/R/Rd2latex.R
===
--- src/library/tools/R/Rd2latex.R  (revision 57751)
+++ src/library/tools/R/Rd2latex.R  (working copy)
@@ -163,10 +163,7 @@
BSL = '@BSL@';
BSL2 = '@BSLBSL@';
#x - fsub(\\dots, ..., x)
-   ## escape any odd \, e.g. \n
-   x - fsub(, BSL, x) # change even ones
x - fsub(\\, BSL2, x)  # odd ones
-   x - fsub(BSL, , x) # change back
x - psub((?!)\\{, {, x)
x - psub((?!)}, }, x)
x - fsub(BSL2, \\bsl{}, x)library(tools)

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel