Re: [R] warnng to an error....

2023-06-19 Thread akshay kulkarni
Dear Martin,
 THanks  for your exhortation!

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Martin Maechler 
Sent: Monday, June 19, 2023 1:15 PM
To: akshay kulkarni 
Cc: Bert Gunter ; R help Mailing list 

Subject: Re: [R] warnng to an error

>>>>> akshay kulkarni
>>>>> on Sat, 17 Jun 2023 18:35:53 + writes:

> Dear Bert, Duncan's theory is workingprobably the same
> as yours...

"theory" .. well *truth*.



Note that I wrote a blog post I had hope would be read more
( --> and be cited more .. when helping peopling with such problems ;-))

Simple search ("google") for  "class think R blog"
or directly
  https://blog.r-project.org/2019/11/09/when-you-think-class.-think-again/

To say it again:   Using  something like

if(... class(x) == "" ..)

is almost always (*) bad code.
Everyone should learn about  inherits() and why sane R code
should use that instead.

---
*)  It may be ok, e.g., when `x` was very expliclitly
constructed in the same part of code a bit earlier

Martin


> THanking you, Yours sincerely, AKSHAY M KULKARNI
>  From: Bert Gunter
>  Sent: Saturday, June 17, 2023
    > 11:28 PM To: akshay kulkarni  Cc: R
> help Mailing list  Subject: Re: [R]
> warnng to an error

> What is class(x) ??

> I think you need to (re?) learn about S3 classes, which
> can in general be vectors. See ?class (the S3 portion) or
> any tutorial on S3 classes in R. I have no idea what you
> are trying to do, but I *suspect* it may be accomplished
> through S3 inheritance rather than changing the class
> vector. That is just a guess, however.

> -- Bert

> On Sat, Jun 17, 2023 at 10:27 AM akshay kulkarni
> mailto:akshay...@hotmail.com>>
> wrote: Dear members, AN update: I have changed the if
> clause to:

> if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code}

> but am bootless.

> PLease help...

> THanking you, Yours sincerely, AKSHAY M KULKARNI

>  From: R-help
> mailto:r-help-boun...@r-project.org>>
> on behalf of akshay kulkarni
> mailto:akshay...@hotmail.com>>
> Sent: Saturday, June 17, 2023 10:46 PM To: R help Mailing
> list mailto:r-help@r-project.org>>
> Subject: [R] warnng to an error

> Dear members,

>   I have the following code:

>> FUN(OHLCDataEP[[63]])
> Error in (class(x) == "xts") || (class(x) == "zoo") :
> 'length = 2' in coercion to 'logical(1)'
>> traceback()
> 2: ygix(x, "c") at #9 1: FUN(OHLCDataEP[[63]])
>> class(OHLCDataEP[[63]])
> [1] "xts" "zoo"

> The following is in ygix() :

> if((class(x) == "xts") || (class(x) == "zoo")

> I think this would have been a warning
> 
(https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
> but I am on a ubuntu22.04 machine with R 4.3.0.

> What should I do? Change it to: if((class(x)[1] == "xts")
> || (class(x)[2] == "zoo")) {code}...

> or is there any workaround?

> THanking you, Yours sincerely, AKSHAY M KULKARNI
> 
[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
> R Warning 'length(x) = 2 > 1' in coercion to
> 
'logical(1)'<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
> Using R 4.1.3 I observe: var - 0 
> if(is.data.frame(var) || is.vector(var)) var -
> as.matrix(var)  is.null(var) || (!is.matrix(var)
>  var == 0) || (dim(var)==c(1,1) 
> stackoverflow.com<http://stackoverflow.com> 



> [[alternative HTML version deleted]]

> __
> R-help@r-project.org<mailto:R-help@r-project.org> mailing
> list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
> read the posting guide
> http://www.R-project.org/posting-guide.html and provide
> commented, minimal, self-contained, reproducible code.

> [[alternative HTML version deleted]]

> __
> R-help@r-project.org<mailto:R-help@r-project.org> mailing
> list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
&

Re: [R] warnng to an error....

2023-06-19 Thread Martin Maechler
>>>>> akshay kulkarni 
>>>>> on Sat, 17 Jun 2023 18:35:53 + writes:

> Dear Bert, Duncan's theory is workingprobably the same
> as yours...

"theory" .. well *truth*.



Note that I wrote a blog post I had hope would be read more
( --> and be cited more .. when helping peopling with such problems ;-))

Simple search ("google") for  "class think R blog"
or directly
  https://blog.r-project.org/2019/11/09/when-you-think-class.-think-again/

To say it again:   Using  something like

if(... class(x) == "" ..)

is almost always (*) bad code.
Everyone should learn about  inherits() and why sane R code
should use that instead.

---
*)  It may be ok, e.g., when `x` was very expliclitly
constructed in the same part of code a bit earlier

Martin


> THanking you, Yours sincerely, AKSHAY M KULKARNI
>  From: Bert Gunter
>  Sent: Saturday, June 17, 2023
    > 11:28 PM To: akshay kulkarni  Cc: R
> help Mailing list  Subject: Re: [R]
> warnng to an error

> What is class(x) ??

> I think you need to (re?) learn about S3 classes, which
> can in general be vectors. See ?class (the S3 portion) or
> any tutorial on S3 classes in R. I have no idea what you
> are trying to do, but I *suspect* it may be accomplished
> through S3 inheritance rather than changing the class
> vector. That is just a guess, however.

> -- Bert

> On Sat, Jun 17, 2023 at 10:27 AM akshay kulkarni
> mailto:akshay...@hotmail.com>>
> wrote: Dear members, AN update: I have changed the if
> clause to:

> if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code}

> but am bootless.

> PLease help...

> THanking you, Yours sincerely, AKSHAY M KULKARNI

>  From: R-help
> mailto:r-help-boun...@r-project.org>>
> on behalf of akshay kulkarni
> mailto:akshay...@hotmail.com>>
> Sent: Saturday, June 17, 2023 10:46 PM To: R help Mailing
> list mailto:r-help@r-project.org>>
> Subject: [R] warnng to an error

> Dear members,

>   I have the following code:

>> FUN(OHLCDataEP[[63]])
> Error in (class(x) == "xts") || (class(x) == "zoo") :
> 'length = 2' in coercion to 'logical(1)'
>> traceback()
> 2: ygix(x, "c") at #9 1: FUN(OHLCDataEP[[63]])
>> class(OHLCDataEP[[63]])
> [1] "xts" "zoo"

> The following is in ygix() :

> if((class(x) == "xts") || (class(x) == "zoo")

> I think this would have been a warning
> 
(https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
> but I am on a ubuntu22.04 machine with R 4.3.0.

> What should I do? Change it to: if((class(x)[1] == "xts")
> || (class(x)[2] == "zoo")) {code}...

> or is there any workaround?

> THanking you, Yours sincerely, AKSHAY M KULKARNI
> 
[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
> R Warning 'length(x) = 2 > 1' in coercion to
> 
'logical(1)'<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
> Using R 4.1.3 I observe: var - 0 
> if(is.data.frame(var) || is.vector(var)) var -
> as.matrix(var)  is.null(var) || (!is.matrix(var)
>  var == 0) || (dim(var)==c(1,1) 
> stackoverflow.com<http://stackoverflow.com> 



> [[alternative HTML version deleted]]

> __
> R-help@r-project.org<mailto:R-help@r-project.org> mailing
> list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
> read the posting guide
> http://www.R-project.org/posting-guide.html and provide
> commented, minimal, self-contained, reproducible code.

> [[alternative HTML version deleted]]

> __
> R-help@r-project.org<mailto:R-help@r-project.org> mailing
> list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
> read the posting guide
> http://www.R-project.org/posting-guide.html and provide
> commented, minimal, self-contained, reproducible code.

>   [[alternative HTML version deleted]]

> __
> R-help@r-project.org maili

Re: [R] warnng to an error....

2023-06-17 Thread akshay kulkarni
Dear Bert,
 Duncan's theory is workingprobably the same as yours...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Bert Gunter 
Sent: Saturday, June 17, 2023 11:28 PM
To: akshay kulkarni 
Cc: R help Mailing list 
Subject: Re: [R] warnng to an error

What is class(x) ??

I think you need to (re?) learn about S3 classes, which can in general be 
vectors. See ?class (the S3 portion) or any tutorial on S3 classes in R. I have 
no idea what you are trying to do, but I *suspect* it may be accomplished 
through S3 inheritance rather than changing the class vector. That is just a 
guess, however.

-- Bert

On Sat, Jun 17, 2023 at 10:27 AM akshay kulkarni 
mailto:akshay...@hotmail.com>> wrote:
Dear members,
  AN update:
I have changed the if clause to:

if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code}

but am bootless.

PLease help...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI


From: R-help 
mailto:r-help-boun...@r-project.org>> on behalf 
of akshay kulkarni mailto:akshay...@hotmail.com>>
Sent: Saturday, June 17, 2023 10:46 PM
To: R help Mailing list mailto:r-help@r-project.org>>
Subject: [R] warnng to an error

Dear members,

  I have the following code:

> FUN(OHLCDataEP[[63]])
Error in (class(x) == "xts") || (class(x) == "zoo") :
  'length = 2' in coercion to 'logical(1)'
> traceback()
2: ygix(x, "c") at #9
1: FUN(OHLCDataEP[[63]])
> class(OHLCDataEP[[63]])
[1] "xts" "zoo"

The following is in ygix() :

if((class(x) == "xts") || (class(x) == "zoo")

I think this would have been a warning 
(https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
 but I am on a ubuntu22.04 machine with R 4.3.0.

What should I do? Change it to:
if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}...

or is there any workaround?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI
[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
R Warning 'length(x) = 2 > 1' in coercion to 
'logical(1)'<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
Using R 4.1.3 I observe: var - 0  if(is.data.frame(var) || 
is.vector(var)) var - as.matrix(var)  is.null(var) || (!is.matrix(var) 
 var == 0) || (dim(var)==c(1,1) 
stackoverflow.com<http://stackoverflow.com>




[[alternative HTML version deleted]]

__
R-help@r-project.org<mailto:R-help@r-project.org> mailing list -- To 
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

__
R-help@r-project.org<mailto:R-help@r-project.org> mailing list -- To 
UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] warnng to an error....

2023-06-17 Thread akshay kulkarni
Dear Duncan,
   THankls a lot...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

From: Duncan Murdoch 
Sent: Saturday, June 17, 2023 11:36 PM
To: akshay kulkarni ; R help Mailing list 

Subject: Re: [R] warnng to an error

On 17/06/2023 1:16 p.m., akshay kulkarni wrote:
> Dear members,
>
>I have the following code:
>
>> FUN(OHLCDataEP[[63]])
> Error in (class(x) == "xts") || (class(x) == "zoo") :
>'length = 2' in coercion to 'logical(1)'
>> traceback()
> 2: ygix(x, "c") at #9
> 1: FUN(OHLCDataEP[[63]])
>> class(OHLCDataEP[[63]])
> [1] "xts" "zoo"
>
> The following is in ygix() :
>
> if((class(x) == "xts") || (class(x) == "zoo")
>
> I think this would have been a warning 
> (https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
>  but I am on a ubuntu22.04 machine with R 4.3.0.
>
> What should I do? Change it to:
> if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}...

Changing it to `if (inherits(x, c("xts", "zoo")))` should do the same.
The vector of classes in the second argument is read as "any of these
classes".

Duncan Murdoch




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] warnng to an error....

2023-06-17 Thread Duncan Murdoch

On 17/06/2023 1:16 p.m., akshay kulkarni wrote:

Dear members,

   I have the following code:


FUN(OHLCDataEP[[63]])

Error in (class(x) == "xts") || (class(x) == "zoo") :
   'length = 2' in coercion to 'logical(1)'

traceback()

2: ygix(x, "c") at #9
1: FUN(OHLCDataEP[[63]])

class(OHLCDataEP[[63]])

[1] "xts" "zoo"

The following is in ygix() :

if((class(x) == "xts") || (class(x) == "zoo")

I think this would have been a warning 
(https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
 but I am on a ubuntu22.04 machine with R 4.3.0.

What should I do? Change it to:
if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}...


Changing it to `if (inherits(x, c("xts", "zoo")))` should do the same. 
The vector of classes in the second argument is read as "any of these 
classes".


Duncan Murdoch

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] warnng to an error....

2023-06-17 Thread Bert Gunter
What is class(x) ??

I think you need to (re?) learn about S3 classes, which can in general be
vectors. See ?class (the S3 portion) or any tutorial on S3 classes in R. I
have no idea what you are trying to do, but I *suspect* it may be
accomplished through S3 inheritance rather than changing the class vector.
That is just a guess, however.

-- Bert

On Sat, Jun 17, 2023 at 10:27 AM akshay kulkarni 
wrote:

> Dear members,
>   AN update:
> I have changed the if clause to:
>
> if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code}
>
> but am bootless.
>
> PLease help...
>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
>
> 
> From: R-help  on behalf of akshay kulkarni <
> akshay...@hotmail.com>
> Sent: Saturday, June 17, 2023 10:46 PM
> To: R help Mailing list 
> Subject: [R] warnng to an error
>
> Dear members,
>
>   I have the following code:
>
> > FUN(OHLCDataEP[[63]])
> Error in (class(x) == "xts") || (class(x) == "zoo") :
>   'length = 2' in coercion to 'logical(1)'
> > traceback()
> 2: ygix(x, "c") at #9
> 1: FUN(OHLCDataEP[[63]])
> > class(OHLCDataEP[[63]])
> [1] "xts" "zoo"
>
> The following is in ygix() :
>
> if((class(x) == "xts") || (class(x) == "zoo")
>
> I think this would have been a warning (
> https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
> but I am on a ubuntu22.04 machine with R 4.3.0.
>
> What should I do? Change it to:
> if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}...
>
> or is there any workaround?
>
> THanking you,
> Yours sincerely,
> AKSHAY M KULKARNI
> [
> https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded
> ]<
> https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1
> >
> R Warning 'length(x) = 2 > 1' in coercion to 'logical(1)'<
> https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1
> >
> Using R 4.1.3 I observe: var - 0  if(is.data.frame(var) ||
> is.vector(var)) var - as.matrix(var)  is.null(var) ||
> (!is.matrix(var)  var == 0) || (dim(var)==c(1,1) 
> stackoverflow.com
> 
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] warnng to an error....

2023-06-17 Thread akshay kulkarni
Dear members,
  AN update:
I have changed the if clause to:

if(class(x)[1] == "xts") || class(x)[2] == "zoo") {code}

but am bootless.

PLease help...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI


From: R-help  on behalf of akshay kulkarni 

Sent: Saturday, June 17, 2023 10:46 PM
To: R help Mailing list 
Subject: [R] warnng to an error

Dear members,

  I have the following code:

> FUN(OHLCDataEP[[63]])
Error in (class(x) == "xts") || (class(x) == "zoo") :
  'length = 2' in coercion to 'logical(1)'
> traceback()
2: ygix(x, "c") at #9
1: FUN(OHLCDataEP[[63]])
> class(OHLCDataEP[[63]])
[1] "xts" "zoo"

The following is in ygix() :

if((class(x) == "xts") || (class(x) == "zoo")

I think this would have been a warning 
(https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
 but I am on a ubuntu22.04 machine with R 4.3.0.

What should I do? Change it to:
if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}...

or is there any workaround?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI
[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
R Warning 'length(x) = 2 > 1' in coercion to 
'logical(1)'<https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1>
Using R 4.1.3 I observe: var - 0  if(is.data.frame(var) || 
is.vector(var)) var - as.matrix(var)  is.null(var) || (!is.matrix(var) 
 var == 0) || (dim(var)==c(1,1) 
stackoverflow.com




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] warnng to an error....

2023-06-17 Thread akshay kulkarni
Dear members,

  I have the following code:

> FUN(OHLCDataEP[[63]])
Error in (class(x) == "xts") || (class(x) == "zoo") :
  'length = 2' in coercion to 'logical(1)'
> traceback()
2: ygix(x, "c") at #9
1: FUN(OHLCDataEP[[63]])
> class(OHLCDataEP[[63]])
[1] "xts" "zoo"

The following is in ygix() :

if((class(x) == "xts") || (class(x) == "zoo")

I think this would have been a warning 
(https://stackoverflow.com/questions/72848442/r-warning-lengthx-2-1-in-coercion-to-logical1)
 but I am on a ubuntu22.04 machine with R 4.3.0.

What should I do? Change it to:
if((class(x)[1] == "xts") || (class(x)[2] == "zoo")) {code}...

or is there any workaround?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI
[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-i...@2.png?v=73d79a89bded]
R Warning 'length(x) = 2 > 1' in coercion to 
'logical(1)'
Using R 4.1.3 I observe: var - 0  if(is.data.frame(var) || 
is.vector(var)) var - as.matrix(var)  is.null(var) || (!is.matrix(var) 
 var == 0) || (dim(var)==c(1,1) 
stackoverflow.com




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.