<div dir="ltr"><div dir="ltr">Hello everyone,<div><br></div><div><div>First of all, let me thank all involved with the Rcpp package!</div><div><br></div><div>I just have a (maybe silly) question, but I struggle with this frequently in my codes:</div><div><br></div><div>Range() vs IntegerVector</div><div><br></div><div>One example is when I need a reverse index, like R's 10:1, so I had to write my own function that returns an IntegerVector. But, to work I have to do this ugly code:</div><div><br></div><div><div style="color:rgb(248,248,248);background-color:rgb(20,20,20);font-size:12.6px;line-height:17px;white-space:pre-wrap"><div>          <span style="color:rgb(155,112,63)">IntegerVector</span> <span style="color:rgb(117,135,166)">dot_rev_idxs1</span> <span style="color:rgb(205,168,105)">=</span> ::<span style="color:rgb(172,136,91);font-weight:bold">seq</span>((<span style="color:rgb(117,135,166)">i</span> <span style="color:rgb(205,168,105)">-</span> <span style="color:rgb(207,106,76)">1</span>), <span style="color:rgb(117,135,166)">beginidx</span>);</div><div>          <span style="color:rgb(155,112,63)">IntegerVector</span> <span style="color:rgb(117,135,166)">dot_rev_idxs2</span> <span style="color:rgb(205,168,105)">=</span> ::<span style="color:rgb(172,136,91);font-weight:bold">seq</span>((<span style="color:rgb(117,135,166)">idx_nn</span> <span style="color:rgb(205,168,105)">-</span> <span style="color:rgb(207,106,76)">1</span>), (<span style="color:rgb(117,135,166)">beginidx</span> <span style="color:rgb(205,168,105)">+</span> <span style="color:rgb(117,135,166)">idx_diff</span>));</div><div>          <span style="color:rgb(155,112,63)">IntegerVector</span> <span style="color:rgb(117,135,166)">dot_rev_idxs3</span> <span style="color:rgb(205,168,105)">=</span> ::<span style="color:rgb(172,136,91);font-weight:bold">seq</span>((<span style="color:rgb(117,135,166)">i</span> <span style="color:rgb(205,168,105)">-</span> <span style="color:rgb(207,106,76)">1</span> <span style="color:rgb(205,168,105)">+</span> <span style="color:rgb(117,135,166)">window_size</span>), (<span style="color:rgb(117,135,166)">beginidx</span> <span style="color:rgb(205,168,105)">+</span> <span style="color:rgb(117,135,166)">window_size</span>));</div><div>          <span style="color:rgb(155,112,63)">IntegerVector</span> <span style="color:rgb(117,135,166)">dot_rev_idxs4</span> <span style="color:rgb(205,168,105)">=</span> ::<span style="color:rgb(172,136,91);font-weight:bold">seq</span>((<span style="color:rgb(117,135,166)">idx_nn</span> <span style="color:rgb(205,168,105)">-</span> <span style="color:rgb(207,106,76)">1</span> <span style="color:rgb(205,168,105)">+</span> <span style="color:rgb(117,135,166)">window_size</span>), (<span style="color:rgb(117,135,166)">beginidx</span> <span style="color:rgb(205,168,105)">+</span> <span style="color:rgb(117,135,166)">idx_diff</span> <span style="color:rgb(205,168,105)">+</span> <span style="color:rgb(117,135,166)">window_size</span>));</div><div>          <span style="color:rgb(117,135,166)">dotproduct</span><span style="color:rgb(172,136,91);font-weight:bold">[</span><span style="color:rgb(117,135,166)">dot_rev_idxs1</span><span style="color:rgb(172,136,91);font-weight:bold">]</span> <span style="color:rgb(172,136,91);font-weight:bold">=</span> (<span style="color:rgb(155,112,63)">NumericVector</span>)((<span style="color:rgb(155,112,63)">NumericVector</span>)<span style="color:rgb(172,136,91);font-weight:bold">cumsum</span>(<span style="color:rgb(117,135,166)">data</span><span style="color:rgb(172,136,91);font-weight:bold">[</span><span style="color:rgb(117,135,166)">dot_rev_idxs1</span><span style="color:rgb(172,136,91);font-weight:bold">]</span> <span style="color:rgb(172,136,91);font-weight:bold">*</span> <span style="color:rgb(117,135,166)">data</span><span style="color:rgb(172,136,91);font-weight:bold">[</span><span style="color:rgb(117,135,166)">dot_rev_idxs2</span><span style="color:rgb(172,136,91);font-weight:bold">]</span> <span style="color:rgb(172,136,91);font-weight:bold">-</span></div><div>                                                                            <span style="color:rgb(117,135,166)">data</span><span style="color:rgb(172,136,91);font-weight:bold">[</span><span style="color:rgb(117,135,166)">dot_rev_idxs3</span><span style="color:rgb(172,136,91);font-weight:bold">]</span> <span style="color:rgb(172,136,91);font-weight:bold">*</span> <span style="color:rgb(117,135,166)">data</span><span style="color:rgb(172,136,91);font-weight:bold">[</span><span style="color:rgb(117,135,166)">dot_rev_idxs4</span><span style="color:rgb(172,136,91);font-weight:bold">]</span>) <span style="color:rgb(172,136,91);font-weight:bold">+</span></div><div>                                                      <span style="color:rgb(117,135,166)">dotproduct</span><span style="color:rgb(172,136,91);font-weight:bold">[</span><span style="color:rgb(117,135,166)">i</span><span style="color:rgb(172,136,91);font-weight:bold">]</span>);</div></div><div><br></div><div>I frequently have to cast the results with <font face="monospace">(NumericVector)</font>...</div><div><br></div><div>This also happens using Range(). But there is a difference if I use Range() this way: <font face="monospace">my_vector[Range(0,10)];</font> or <font face="monospace">Range range = Range(0, 10); my_vector[range];</font><br clear="all"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">How is the proper way to deal with it? </span></div><div><span style="font-size:12.8px"><font face="monospace"><br></font></span></div><div><font face="arial, sans-serif" style="font-size:12.8px">Other question: </font><font face="monospace" style="font-size:12.8px">as<NumericVector() </font><span style="font-size:12.8px">doesn't 'cast' right? Does it try to 'convert' formats?</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">And finally, I see that Matlab has a unique way to deal with ranges:</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Ex.:</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px"><font face="monospace">1) (1:10) --> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10</font></span></div><div><span style="font-size:12.8px"><font face="monospace">2) (10:1) --> returns a vector with size zero</font></span></div><div><span style="font-size:12.8px"><font face="monospace">3) (10:-1:1) --> 10, 9, 8, 7, 6, 5, 4, 3, 2, 1</font></span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Range() shouldn't at least reproduce the R's counterpart and accept <font face="monospace">Range(10,1) == 10:1</font>?</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Thanks in advance!</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">my package: <a href="https://mailtrack.io/trace/link/9b0962ae6d75a7caaaf14e3c8d77db64148aabc1?url=https%3A%2F%2Fcran.r-project.org%2Fpackage%3Dtsmp&userId=3785237&signature=c65e6b4074bf11ac" target="_blank">https://CRAN.R-project.org/package=tsmp</a></span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><div><br clear="all"><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span style="font-size:12.8px">--</span><br style="font-size:12.8px"><span style="font-size:large">Francisco Bischoff, MD, MSc</span></div><div>Faculty of Medicine of the University of Porto, Portugal<br></div><div><br></div><div dir="ltr">- Master of Medical Informatics | topic: time series<br>- Research Associate | <a href="https://mailtrack.io/trace/link/93d55bc6ee2a8fc10541d0274f3fde245e944698?url=http%3A%2F%2Fcintesis.eu%2Fai4health%2F&userId=3785237&signature=decc8b53c66739e9" target="_blank">artificial intelligence for health</a> @ <a href="https://mailtrack.io/trace/link/02df11fcc383816c96681205a4142a6ccb60bfaa?url=http%3A%2F%2Fcintesis.eu&userId=3785237&signature=9d174b79c4ee78b7" target="_blank">cintesis.eu</a><br>- Teaching Assistant | department of community medicine, information and health decision sciences @ <a href="https://mailtrack.io/trace/link/50de7c0f37c419aafee22f9492fdfdbd1da63c1d?url=http%3A%2F%2Fmed.up.pt&userId=3785237&signature=66de0e074d671cf7" target="_blank">med.up.pt</a><br><br>ORCID: 0000-0002-5301-8672 | Mendeley: francisco-bischoff | Google: tCeA0uUAAAAJ | ResearcherID: H-8261-2016 | ResearchGate: Francisco_Bischoff | CiênciaID B413-E0A0-DE8D | LinkedIn: franzbischoff</div></div></div></div></div></div></div></div></div></div></div></div></div></div><br><br><i>"Quality is not an act, it is a habit."<br>-- Aristotle</i><br><br></div></div><img width="0" height="0" class="mailtrack-img" alt="" style="display:flex" src="https://mailtrack.io/trace/mail/2e0aa4201a35ad2c338bece0c5ad3a6083eee128.png?u=3785237"></div>