Le 02/04/13 17:57, Dirk Eddelbuettel a écrit :
I agree with everybody too :)
I still like my example, and I obviously respect operator- "in general".
What I can't square is whether the code for operator- (which I may in fact
have defined the way I like it) _actually gets called_.
Of course it is called.
If I switch your code to
int operator-(const Date& d1, const Date& d2) {
Rprintf( "d1 = %d\n", d1.m_d ) ;
Rprintf( "d2 = %d\n", d2.m_d ) ;
int diff = d2.m_d - d1.m_d;
Rprintf( "diff = %d\n", diff );
return diff ;
}
or similar in class Datetime.
> NewYear <- as.Date("2013-01-01")
> Easter <- Sys.Date()
> cppFunction('double ddiff(Date a, Date b) { return a - b; }')
> cppFunction('double ddiff2(Date a, Date b) { return b - a; }')
> ddiff(NewYear, Easter)
d1 = 1606400880
d2 = 1606389816
diff = 91
[1] 91
> ddiff2(NewYear, Easter)
d1 = 1606400944
d2 = 1606389816
diff = -91
[1] -91
This is getting ridiculous.
In what I sent on March 31 as the NewYear/Easter example:
R> NewYear <- as.Date("2013-01-01")
R> Easter <- Sys.Date()
R> cppFunction('double ddiff(Date a, Date b) { return a - b; }')
R> cppFunction('double ddiff2(Date a, Date b) { return b - a; }')
R> ddiff(NewYear, Easter)
[1] 89 ## I find this more logical
R> ddiff2(NewYear, Easter)
[1] -89 ## closer to R's difftime and 'odd' to me
R>
If it isn't used here, where is it actually used?
Dirk
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
R Graph Gallery: http://gallery.r-enthusiasts.com
blog: http://blog.r-enthusiasts.com
|- http://bit.ly/ZTFLDo : Simpler R help tooltips
`- http://bit.ly/YFsziW : R Help tooltips
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel