On 16 January 2021 at 01:35, Francisco Bischoff wrote: | About the Range() function, I think it should handle decreasing ranges | too... | But, idk if using Matlabs approach or R approach: | | R's: | | a <- 1 | b <- 10 | | print(a:b) | 1 2 3 4 5 6 7 8 9 10 | print(b:a) | 10 9 8 7 6 5 4 3 2 1 | | Matlab's | a = 1; | b = 10; | disp(a:b); | 1 2 3 4 5 6 7 8 9 10 | disp(b:a); | numeric(0) | disp(b:-1:a) | 10 9 8 7 6 5 4 3 2 1 | | I think that we are in the R domain, so we should use Range(b, a) normally | (my humble opinion).
Hm but I think the Range class in Rcpp is not the same as R's seq(). It is used internally in a few places and may not generalize well to the 'b:-1:a' use. I had a quick look, and Armadillo may not have anything directly relevant either. linspace() is close but not quite the same. I would probably just write myself a little helper function. | About Casting, this is a good example: | | Rcout << Range(0, 10) << std::endl; | | This does not compute... | | What should I do? | | Rcout << as<IntegerVector>(Range(0, 10)) << std::endl; | or | Rcout << (IntegerVector)(Range(0, 10)) << std::endl; That can happen as template expressions can get in the way. Alternatives are maybe using Armadillo types for, again, just using a quick loop and printing elements. Rcpp has a lot of functions. But it doesn't have "all of R's functions" and should not be seen as aiming for that. Dirk -- https://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel