[R] warnng to an error....

akshay kulkarni @k@h@y_e4 @end|ng |rom hotm@||@com
Sat Jun 17 20:34:11 CEST 2023


Dear Duncan,
                       THankls a lot...

THanking you,
Yours sincerely,
AKSHAY M KULKARNI
________________________________
From: Duncan Murdoch <murdoch.duncan using gmail.com>
Sent: Saturday, June 17, 2023 11:36 PM
To: akshay kulkarni <akshay_e4 using hotmail.com>; R help Mailing list <r-help using r-project.org>
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 <tmp>#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]]



More information about the R-help mailing list