Re: [Rd] NOTE: multiple local function definitions for ?fun? with different formal arguments

2024-02-06 Thread Duncan Murdoch

On 06/02/2024 2:17 p.m., Hervé Pagès wrote:
Thanks. Workarounds are interesting but... what's the point of the NOTE 
in the first place?


Creating a function that can't be called could be an error.  Presumably 
you are careful and never try to call it with the wrong signature, but 
the check code isn't smart enough to follow every code path, so it gives 
the note to warn you that you might have something wrong.


You still have the same issue with my workaround, but the check code 
isn't smart enough to notice that.


Duncan Murdoch



H.

On 2/4/24 09:07, Duncan Murdoch wrote:
On 04/02/2024 10:55 a.m., Izmirlian, Grant (NIH/NCI) [E] via R-devel 
wrote:
Well you can see that yeast is exactly weekday you have.  The way out 
is to just not name the result


I think something happened to your explanation...



toto <- function(mode)
{
 ifelse(mode == 1,
 function(a,b) a*b,
 function(u, v, w) (u + v) / w)
}


It's a bad idea to use ifelse() when you really want if() ... else ... 
.  In this case it works, but it doesn't always.  So the workaround 
should be



toto <- function(mode)
{
    if(mode == 1)
    function(a,b) a*b
    else
    function(u, v, w) (u + v) / w
}






From: Grant Izmirlian 
Date: Sun, Feb 4, 2024, 10:44 AM
To: "Izmirlian, Grant (NIH/NCI) [E]" 
Subject: Fwd: [EXTERNAL] R-devel Digest, Vol 252, Issue 2

Hi,

I just ran into this 'R CMD check' NOTE for the first time:

* checking R code for possible problems ... NOTE
toto: multiple local function definitions for �fun� with different
   formal arguments

The "offending" code is something like this (simplified from the real 
code):


toto <- function(mode)
{
 if (mode == 1)
 fun <- function(a, b) a*b
 else
 fun <- function(u, v, w) (u + v) / w
 fun
}

Is that NOTE really intended? Hard to see why this code would be
considered "wrong".

I know it's just a NOTE but still...


I agree it's a false positive, but the issue is that you have a 
function object in your function which can't be called 
unconditionally.  The workaround doesn't create such an object.


Recognizing that your function never tries to call fun requires global 
inspection of toto(), and most of the checks are based on local 
inspection.


Duncan Murdoch

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


--
Hervé Pagès

Bioconductor Core Team
hpages.on.git...@gmail.com



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


Re: [Rd] NOTE: multiple local function definitions for ?fun? with different formal arguments

2024-02-06 Thread Hervé Pagès
Thanks. Workarounds are interesting but... what's the point of the NOTE 
in the first place?

H.

On 2/4/24 09:07, Duncan Murdoch wrote:
> On 04/02/2024 10:55 a.m., Izmirlian, Grant (NIH/NCI) [E] via R-devel 
> wrote:
>> Well you can see that yeast is exactly weekday you have.  The way out 
>> is to just not name the result
>
> I think something happened to your explanation...
>
>>
>> toto <- function(mode)
>> {
>>  ifelse(mode == 1,
>>  function(a,b) a*b,
>>  function(u, v, w) (u + v) / w)
>> }
>
> It's a bad idea to use ifelse() when you really want if() ... else ... 
> .  In this case it works, but it doesn't always.  So the workaround 
> should be
>
>
> toto <- function(mode)
> {
>     if(mode == 1)
>     function(a,b) a*b
>     else
>     function(u, v, w) (u + v) / w
> }
>
>
>>
>>
>> 
>> From: Grant Izmirlian 
>> Date: Sun, Feb 4, 2024, 10:44 AM
>> To: "Izmirlian, Grant (NIH/NCI) [E]" 
>> Subject: Fwd: [EXTERNAL] R-devel Digest, Vol 252, Issue 2
>>
>> Hi,
>>
>> I just ran into this 'R CMD check' NOTE for the first time:
>>
>> * checking R code for possible problems ... NOTE
>> toto: multiple local function definitions for �fun� with different
>>    formal arguments
>>
>> The "offending" code is something like this (simplified from the real 
>> code):
>>
>> toto <- function(mode)
>> {
>>  if (mode == 1)
>>  fun <- function(a, b) a*b
>>  else
>>  fun <- function(u, v, w) (u + v) / w
>>  fun
>> }
>>
>> Is that NOTE really intended? Hard to see why this code would be
>> considered "wrong".
>>
>> I know it's just a NOTE but still...
>
> I agree it's a false positive, but the issue is that you have a 
> function object in your function which can't be called 
> unconditionally.  The workaround doesn't create such an object.
>
> Recognizing that your function never tries to call fun requires global 
> inspection of toto(), and most of the checks are based on local 
> inspection.
>
> Duncan Murdoch
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Hervé Pagès

Bioconductor Core Team
hpages.on.git...@gmail.com

[[alternative HTML version deleted]]

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


Re: [Rd] NOTE: multiple local function definitions for ?fun? with different formal arguments

2024-02-04 Thread Duncan Murdoch

On 04/02/2024 10:55 a.m., Izmirlian, Grant (NIH/NCI) [E] via R-devel wrote:

Well you can see that yeast is exactly weekday you have.  The way out is to 
just not name the result


I think something happened to your explanation...



toto <- function(mode)
{
 ifelse(mode == 1,
 function(a,b) a*b,
 function(u, v, w) (u + v) / w)
}


It's a bad idea to use ifelse() when you really want if() ... else ... . 
 In this case it works, but it doesn't always.  So the workaround should be



toto <- function(mode)
{
if(mode == 1)
function(a,b) a*b
else
function(u, v, w) (u + v) / w
}






From: Grant Izmirlian 
Date: Sun, Feb 4, 2024, 10:44 AM
To: "Izmirlian, Grant (NIH/NCI) [E]" 
Subject: Fwd: [EXTERNAL] R-devel Digest, Vol 252, Issue 2

Hi,

I just ran into this 'R CMD check' NOTE for the first time:

* checking R code for possible problems ... NOTE
toto: multiple local function definitions for �fun� with different
   formal arguments

The "offending" code is something like this (simplified from the real code):

toto <- function(mode)
{
 if (mode == 1)
 fun <- function(a, b) a*b
 else
 fun <- function(u, v, w) (u + v) / w
 fun
}

Is that NOTE really intended? Hard to see why this code would be
considered "wrong".

I know it's just a NOTE but still...


I agree it's a false positive, but the issue is that you have a function 
object in your function which can't be called unconditionally.  The 
workaround doesn't create such an object.


Recognizing that your function never tries to call fun requires global 
inspection of toto(), and most of the checks are based on local inspection.


Duncan Murdoch

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


[Rd] NOTE: multiple local function definitions for ?fun? with different formal arguments

2024-02-04 Thread Izmirlian, Grant (NIH/NCI) [E] via R-devel
Well you can see that yeast is exactly weekday you have.  The way out is to 
just not name the result

toto <- function(mode)
{
ifelse(mode == 1,
function(a,b) a*b,
function(u, v, w) (u + v) / w)
}



From: Grant Izmirlian 
Date: Sun, Feb 4, 2024, 10:44 AM
To: "Izmirlian, Grant (NIH/NCI) [E]" 
Subject: Fwd: [EXTERNAL] R-devel Digest, Vol 252, Issue 2

Hi,

I just ran into this 'R CMD check' NOTE for the first time:

* checking R code for possible problems ... NOTE
toto: multiple local function definitions for �fun� with different
  formal arguments

The "offending" code is something like this (simplified from the real code):

toto <- function(mode)
{
if (mode == 1)
fun <- function(a, b) a*b
else
fun <- function(u, v, w) (u + v) / w
fun
}

Is that NOTE really intended? Hard to see why this code would be
considered "wrong".

I know it's just a NOTE but still...

Thanks,

H.

--
Herv� Pag�s

Bioconductor Core Team
hpages.on.git...@gmail.com


CAUTION: This email originated from outside of the organization. Do not click 
links or open attachments unless you recognize the sender and are confident the 
content is safe.


[[alternative HTML version deleted]]

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


[Rd] NOTE: multiple local function definitions for ‘fun’ with different formal arguments

2024-02-03 Thread Hervé Pagès
Hi,

I just ran into this 'R CMD check' NOTE for the first time:

* checking R code for possible problems ... NOTE
toto: multiple local function definitions for ‘fun’ with different
   formal arguments

The "offending" code is something like this (simplified from the real code):

toto <- function(mode)
{
     if (mode == 1)
     fun <- function(a, b) a*b
     else
     fun <- function(u, v, w) (u + v) / w
     fun
}

Is that NOTE really intended? Hard to see why this code would be 
considered "wrong".

I know it's just a NOTE but still...

Thanks,

H.

-- 
Hervé Pagès

Bioconductor Core Team
hpages.on.git...@gmail.com

[[alternative HTML version deleted]]

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