From tom@@@k@liber@ @ending from gm@il@com  Fri Jun  1 11:33:29 2018
From: tom@@@k@liber@ @ending from gm@il@com (Tomas Kalibera)
Date: Fri, 1 Jun 2018 11:33:29 +0200
Subject: [Rd] user macros with multi-line arguments in Rd (was Re: Rd parser
 throws error for user macros invoked with empty argument)
In-Reply-To: <438D2EC9EAFE5946B2D5864670EA468E018F65AF5A@MBXP01.ds.man.ac.uk>
References: <438D2EC9EAFE5946B2D5864670EA468E018F659ED0@MBXP01.ds.man.ac.uk>
 <36099164-4dc8-0153-1210-960f6d6dd277@gmail.com>
 <438D2EC9EAFE5946B2D5864670EA468E018F65AF5A@MBXP01.ds.man.ac.uk>
Message-ID: <8f8a37aa-8461-1419-86e3-ae3b23e41b23@gmail.com>

Thanks for the report, I am testing a patch that will allow multi-line 
arguments to user macros.

Best
Tomas

On 05/25/2018 04:45 PM, Georgi Boshnakov wrote:
> While on the topic of Rd macro arguments, it seems that  if a multiline argument is supplied, the lines after the first are silently ignored:
>
> f <- tempfile()
> mac6 <- "\\newcommand{\\mac6}{mac6: #1}"
>
> cat(mac6, "\\mac6{2*3
> 2+2
> sin(pi)
> }\n", file = f)
> rd <- tools::parse_Rd(f)
>
>> rd
>   mac6: 2*3
>
> ---
>
> Georgi Boshnakov
>
>
> -----Original Message-----
> From: Tomas Kalibera [mailto:tomas.kalibera at gmail.com]
> Sent: 25 May 2018 10:05
> To: Georgi Boshnakov; r-devel at r-project.org
> Subject: Re: [Rd] Rd parser throws error for user macros invoked with empty argument
>
> Thanks for the report and the examples - and they do not have to be that
> verbose, it is enough to just define and use a command, e.g.
>
> cat("\\newcommand{\\mac1}{MAC1:#1}\\mac1{}", file=f)
> rd <- tools::parse_Rd(f)
>
> Whenever you get an error message like "Value of SET_STRING_ELT() must
> be a 'CHARSXP' not a 'NULL'", there is a bug (at least the error message
> should be relevant/informative).
>
> I am testing a patch that will allow empty arguments to macros (they
> will expand to an empty string, like in LaTeX).
>
> Best
> Tomas
>
> On 05/14/2018 11:23 PM, Georgi Boshnakov wrote:
>> Bug or feature?
>>
>> I get the following error from parse_Rd() when a user Rd macro (including system ones) is invoked with empty argument {},
>> eg \mymacro{}:
>>
>> Error in tools::parse_Rd(fn) :
>>     Value of SET_STRING_ELT() must be a 'CHARSXP' not a 'NULL'
>>
>> A full example is further below with the system macro \CRANpkg{}. In this example it doesn't make sense to use empty argument but the error is not specific to this particular macro.
>>
>> ------
>> Georgi Boshnakov
>>
>>
>> Create an Rd file containing system macro \CRANpkg{bibtex}, parse_Rd() is ok:
>>
>> =================
>> fn <- tempfile()
>> writeLines("\\name{dummyfun}
>> \\alias{dummyfun}
>> \\title{Dummy title}
>> \\description{Dummy description}
>> \\usage{
>> dummyfun(x, ...)
>> }
>> \\arguments{
>>     \\item{x}{a value.}
>>     \\item{\\dots}{further arguments.}
>> }
>> \\details{
>>       \\CRANpkg{bibtex}
>> }
>> ", fn)
>>
>>> tools::parse_Rd(fn)
>> ...
>> \details{
>>       \href{{https://CRAN.R-project.org/package=bibtex}{\pkg{bibtex}}}
>> }
>>
>> ================
>>
>> With empty argument - \CRANpkg{} - Rd parser throws error. Of course it is silly in this example but I have used it with other user defined  macros where it may make sense to have empty argument.
>>
>> ================
>>> writeLines("\\name{dummyfun}
>> \\alias{dummyfun}
>> \\title{Dummy title}
>> \\description{Dummy description}
>> \\usage{
>> dummyfun(x, ...)
>> }
>> \\arguments{
>>     \\item{x}{a value.}
>>     \\item{\\dots}{further arguments.}
>> }
>> \\details{
>>       \\CRANpkg{}
>> }
>> ", fn)
>>> tools::parse_Rd(fn)
>> Error in tools::parse_Rd(fn) :
>>     Value of SET_STRING_ELT() must be a 'CHARSXP' not a 'NULL'
>>
>> 	[[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] user macros with multi-line arguments in Rd (was Re: Rd parser throws error for user macros invoked with empty argument)
Tomas Kalibera