Re: [R-pkg-devel] Workaround for code/documentation mismatch

2021-08-11 Thread Andrew Simmons
Hello,


@Martin Maechler:
%until% and %while% use R's builtin repeat function. Something like

do(expr) %until% (cond)
repeat {
expr
if (cond)
break
}

are identical. After %until% and %while% check the arguments look correct,
it makes a call to repeat like above and evaluates it in the same
environment as %until% or %while% was called from. I haven't completely
reinvented the wheel here.
%until% and %while% are slower than repeat, but only by a microsecond or
two.
Admittedly, my documentation for %until% and %while% is dog water compared
to repeat, but I've tried to make it as clear as possible in my
documentation that %until% and %while% use repeat,
and included the link to the documentation for repeat.


@Duncan Murdoch:
I'll try renaming the arguments, thank you for the suggestion. Also, I
didn't realize you could put R comments in \usage with #, so I might try
that as well, thank you!

[[alternative HTML version deleted]]

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


Re: [R-pkg-devel] Workaround for code/documentation mismatch

2021-08-11 Thread Duncan Murdoch

On 10/08/2021 11:25 p.m., Andrew Simmons wrote:

Hello,


I've written two functions to emulate do while/until loops seen in other
languages, but I'm having trouble documenting its usage. The function is
typically used like:

do ({
 expr1
 expr2
 ...
}) %while% (cond)

so I want to document it something like:

do(expr) %while% (cond)
do(expr) %until% (cond)

to look like the documentation for 'while' and 'if', but R CMD check
produces a "Code/documentation mismatch" warning, complaining that the
documentation should look like:

expr %while% cond
expr %until% cond

So, my question is, is there a way to bypass the
* checking for code/documentation mismatches
portion of R CMD check, at least for one file? Some way to acknowledge that
the code and documentation will mismatch, but that's okay.



I think the answer is no.  What I'd do is name the first argument to the 
operator in a way to indicate that it must be the result of do() and the 
second to indicate it must be parenthesized (if that's a 
requirement...), e.g.


`%while%` <- function(do_expr, parenthesized_cond) { ... }

and then document as

do_expr %while% parenthesized_cond

in the \usage section, and document standard usage in the \details 
section and examples.


Duncan Murdoch

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


Re: [R-pkg-devel] Workaround for code/documentation mismatch

2021-08-11 Thread Martin Maechler
> Hello,
> 
> I've written two functions to emulate do while/until loops seen in other
> languages, but I'm having trouble documenting its usage. The function is
> typically used like:
> 
> do ({
> expr1
> expr2
> ...
> }) %while% (cond)

I understand that you did *not* ask .. but really
why don't you want to use R's own
builtin, fast, well documented, present everywhere *and* simpler syntax

while(cond) {
  expr1
  expr2
  ...
}   

???

and also

   repeat {
 expr1
 expr2
 
 if(cond) break
   }

instead of your   %until%  below?


> so I want to document it something like:
> 
> do(expr) %while% (cond)
> do(expr) %until% (cond)
> 
> to look like the documentation for 'while' and 'if', but R CMD check
> produces a "Code/documentation mismatch" warning, complaining that the
> documentation should look like:
> 
> expr %while% cond
> expr %until% cond
> 
> So, my question is, is there a way to bypass the
> * checking for code/documentation mismatches
> portion of R CMD check, at least for one file? Some way to acknowledge that
> the code and documentation will mismatch, but that's okay.
> 
> 
> Thank you!

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


Re: [R-pkg-devel] Workaround for code/documentation mismatch

2021-08-10 Thread Andrew Simmons
When not preceded by an expression wrapped in do(), %while% would throw an
error "do while loop must begin with 'do'". The function %while% looks like

`%while%` <- function (expr, cond)
invisible(.Call(C_do.while, substitute(expr), substitute(cond),
parent.frame()))

and the corresponding C function looks like

SEXP do_dowhile(SEXP expr, SEXP cond, SEXP rho)
{
/* we're looking for an expression of the form
   do ( expr )
   do ( { expr1 ; expr2 } )

   there must NOT be a tag on the second item, the expression within
'do'
   that is, we reject expressions of the form

   do (var = expr)
   do (var = { expr1 ; expr2 } ) */
if (TYPEOF(expr) != LANGSXP || CAR(expr) != install("do"))
error("do while loop must begin with 'do'");
else if (xlength(expr) != 2 || !isNull(TAG(CDR(expr
error("invalid 'expr'");

The 'do' part of the expression is irrelevant and later removed, it's only
required because it makes the syntax look more like other languages.
So the proper way to use %while% is
expr %while% cond
where expr is wrapped with do(), but I think it would be far more
understandable in the usage documentation to have it look like
do(expr) %while% (cond)

If it helps at all with context, I'll provide the R and C scripts I'm using.

On Tue, Aug 10, 2021 at 11:47 PM Hugh Parsonage 
wrote:

> What is the behaviour of %while% if not preceded by an expression wrapped
> in do() ?
>
> On Wed, 11 Aug 2021 at 1:26 pm, Andrew Simmons  wrote:
>
>> Hello,
>>
>>
>> I've written two functions to emulate do while/until loops seen in other
>> languages, but I'm having trouble documenting its usage. The function is
>> typically used like:
>>
>> do ({
>> expr1
>> expr2
>> ...
>> }) %while% (cond)
>>
>> so I want to document it something like:
>>
>> do(expr) %while% (cond)
>> do(expr) %until% (cond)
>>
>> to look like the documentation for 'while' and 'if', but R CMD check
>> produces a "Code/documentation mismatch" warning, complaining that the
>> documentation should look like:
>>
>> expr %while% cond
>> expr %until% cond
>>
>> So, my question is, is there a way to bypass the
>> * checking for code/documentation mismatches
>> portion of R CMD check, at least for one file? Some way to acknowledge
>> that
>> the code and documentation will mismatch, but that's okay.
>>
>>
>> Thank you!
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-package-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>>
>
__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Workaround for code/documentation mismatch

2021-08-10 Thread Hugh Parsonage
What is the behaviour of %while% if not preceded by an expression wrapped
in do() ?

On Wed, 11 Aug 2021 at 1:26 pm, Andrew Simmons  wrote:

> Hello,
>
>
> I've written two functions to emulate do while/until loops seen in other
> languages, but I'm having trouble documenting its usage. The function is
> typically used like:
>
> do ({
> expr1
> expr2
> ...
> }) %while% (cond)
>
> so I want to document it something like:
>
> do(expr) %while% (cond)
> do(expr) %until% (cond)
>
> to look like the documentation for 'while' and 'if', but R CMD check
> produces a "Code/documentation mismatch" warning, complaining that the
> documentation should look like:
>
> expr %while% cond
> expr %until% cond
>
> So, my question is, is there a way to bypass the
> * checking for code/documentation mismatches
> portion of R CMD check, at least for one file? Some way to acknowledge that
> the code and documentation will mismatch, but that's okay.
>
>
> Thank you!
>
> [[alternative HTML version deleted]]
>
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

[[alternative HTML version deleted]]

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


[R-pkg-devel] Workaround for code/documentation mismatch

2021-08-10 Thread Andrew Simmons
Hello,


I've written two functions to emulate do while/until loops seen in other
languages, but I'm having trouble documenting its usage. The function is
typically used like:

do ({
expr1
expr2
...
}) %while% (cond)

so I want to document it something like:

do(expr) %while% (cond)
do(expr) %until% (cond)

to look like the documentation for 'while' and 'if', but R CMD check
produces a "Code/documentation mismatch" warning, complaining that the
documentation should look like:

expr %while% cond
expr %until% cond

So, my question is, is there a way to bypass the
* checking for code/documentation mismatches
portion of R CMD check, at least for one file? Some way to acknowledge that
the code and documentation will mismatch, but that's okay.


Thank you!

[[alternative HTML version deleted]]

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