[Rcpp-devel] Ranges and Casting

Francisco Bischoff fbischoff at med.up.pt
Sat Jan 16 03:05:05 CET 2021


Thanks for the tips.

Still, Range() is the correct way to write:

NumericVector my_vec(200);

my_vec(Range(0,10)) = 10;

?

Thanks in advance




--
Francisco Bischoff, MD, MSc
Faculty of Medicine of the University of Porto, Portugal

- Master of Medical Informatics | topic: time series
- Research Associate | artificial intelligence for health
<https://mailtrack.io/trace/link/1765b288bbce44d233e851a8d862ec594378aa04?url=http%3A%2F%2Fcintesis.eu%2Fai4health%2F&userId=3785237&signature=1b62d7a180130981>
@ cintesis.eu
<https://mailtrack.io/trace/link/89b15c4212d5d6c8d4ba354ec92ab002ba9a96ef?url=http%3A%2F%2Fcintesis.eu&userId=3785237&signature=5fa97b31373fa664>
- Teaching Assistant | department of community medicine, information and
health decision sciences @ med.up.pt
<https://mailtrack.io/trace/link/32f5f446b7bc0d597241524764b3636b5a75d466?url=http%3A%2F%2Fmed.up.pt&userId=3785237&signature=cfbca25f5fe210b3>

ORCID: 0000-0002-5301-8672 | Mendeley: francisco-bischoff | Google:
tCeA0uUAAAAJ | ResearcherID: H-8261-2016 | ResearchGate: Francisco_Bischoff
| CiênciaID B413-E0A0-DE8D | LinkedIn: franzbischoff


On Sat, Jan 16, 2021 at 1:54 AM Dirk Eddelbuettel <edd at debian.org> wrote:

>
> 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
> <https://mailtrack.io/trace/link/ec16eaacf00108f6b925d8cd55d469ea736d3313?url=https%3A%2F%2Fdirk.eddelbuettel.com&userId=3785237&signature=5ff5161e5ff16475>
> | @eddelbuettel | edd at debian.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20210116/20aacb04/attachment-0001.html>


More information about the Rcpp-devel mailing list