Hi Folks,
What is the best way to avoid a function being read in
anew (and masking an exiting function) when a definition
of it has already been established in R?
Reason: Fernando Tusell and I are working up Schafer's 'CAT'
for R (basically done now, just needs some cosmetic tidying up).
This uses a function 'slice.index', present in S but not in
the versions of R we were working with at the time. So we put
in a definition (copied from R-help ... ).
However, it seems that slice.index is now in "base" in latest
versions of R. So it would seem a bit silly to read it in anew.
Nevertheless, probably we should keep it in for the sake of people
still using older versions of R who would not have it.
So what's the best method to do
if( some test for function slice.index absent ) {
slice.index<-function(....){....}
}
??
Thanks,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 20-Sep-03 Time: 15:07:59
------------------------------ XFMail ------------------------------
Have you considered:
> exists("slice.index")
[1] TRUE
In other circumstances, I've tested various components of
"version".
hope this helps.
spencer graves
(Ted Harding) wrote:
>Hi Folks,
>
>What is the best way to avoid a function being read in
>anew (and masking an exiting function) when a definition
>of it has already been established in R?
>
>Reason: Fernando Tusell and I are working up Schafer's 'CAT'
>for R (basically done now, just needs some cosmetic tidying up).
>
>This uses a function 'slice.index', present in S but not in
>the versions of R we were working with at the time. So we put
>in a definition (copied from R-help ... ).
>
>However, it seems that slice.index is now in "base" in latest
>versions of R. So it would seem a bit silly to read it in anew.
>Nevertheless, probably we should keep it in for the sake of people
>still using older versions of R who would not have it.
>
>So what's the best method to do
>
>if( some test for function slice.index absent ) {
> slice.index<-function(....){....}
>}
>
>??
>
>Thanks,
>Ted.
>
>
>--------------------------------------------------------------------
>E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
>Fax-to-email: +44 (0)870 167 1972
>Date: 20-Sep-03 Time: 15:07:59
>------------------------------ XFMail ------------------------------
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>
On 20 Sep 2003 at 15:07, Ted Harding wrote: What about> exists("slice.index")[1] TRUE Kjetil Halvorsen> Hi Folks, > > What is the best way to avoid a function being read in > anew (and masking an exiting function) when a definition > of it has already been established in R? > > Reason: Fernando Tusell and I are working up Schafer's 'CAT' > for R (basically done now, just needs some cosmetic tidying up). > > This uses a function 'slice.index', present in S but not in > the versions of R we were working with at the time. So we put > in a definition (copied from R-help ... ). > > However, it seems that slice.index is now in "base" in latest > versions of R. So it would seem a bit silly to read it in anew. > Nevertheless, probably we should keep it in for the sake of people > still using older versions of R who would not have it. > > So what's the best method to do > > if( some test for function slice.index absent ) { > slice.index<-function(....){....} > } > > ?? > > Thanks, > Ted. > > > -------------------------------------------------------------------- > E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> > Fax-to-email: +44 (0)870 167 1972 > Date: 20-Sep-03 Time: 15:07:59 > ------------------------------ XFMail ------------------------------ > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
"(Ted Harding)" wrote:> > Hi Folks, > > What is the best way to avoid a function being read in > anew (and masking an exiting function) when a definition > of it has already been established in R? > > Reason: Fernando Tusell and I are working up Schafer's 'CAT' > for R (basically done now, just needs some cosmetic tidying up). > > This uses a function 'slice.index', present in S but not in > the versions of R we were working with at the time. So we put > in a definition (copied from R-help ... ). > > However, it seems that slice.index is now in "base" in latest > versions of R. So it would seem a bit silly to read it in anew. > Nevertheless, probably we should keep it in for the sake of people > still using older versions of R who would not have it. > > So what's the best method to do > > if( some test for function slice.index absent ) { > slice.index<-function(....){....} > } > > ?? > > Thanks, > Ted. > > -------------------------------------------------------------------- > E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> > Fax-to-email: +44 (0)870 167 1972 > Date: 20-Sep-03 Time: 15:07:59 > ------------------------------ XFMail ------------------------------ > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-helpBeside the other answers (mentioning exists()), I'd like to point out that R has Namespace support these days. It would not help for users of outdated versions of R, though. Uwe Ligges