Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/temporal types #58

Merged
merged 32 commits into from
Mar 23, 2020
Merged

Feature/temporal types #58

merged 32 commits into from
Mar 23, 2020

Conversation

lsilvest
Copy link
Collaborator

OK, this is a huge pull request.

I think the code is complete, and we've got 100% coverage.

There's still no vignette and I'll be working on that, but I thought in the mean time that it would be worthwhile going through a code review (which is also a great way for me to take a step back and look at the new code in its whole).

I will explain the main changes going in. Some are obvious (e.g. new types), so are more subtle like relaxed format, etc.

lsilvest and others added 22 commits November 27, 2019 15:56
@codecov
Copy link

codecov bot commented Mar 15, 2020

Codecov Report

Merging #58 into master will decrease coverage by 0.05%.
The diff coverage is 99.94%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #58      +/-   ##
==========================================
- Coverage     100%   99.94%   -0.06%     
==========================================
  Files           1       14      +13     
  Lines          97     1849    +1752     
==========================================
+ Hits           97     1848    +1751     
- Misses          0        1       +1
Impacted Files Coverage Δ
inst/include/date.h 100% <ø> (ø)
src/duration.cpp 100% <100%> (ø)
inst/include/interval.hpp 100% <100%> (ø)
R/nanoival.R 100% <100%> (ø)
R/nanoperiod.R 100% <100%> (ø)
inst/include/utilities.hpp 100% <100%> (ø)
R/nanoduration.R 100% <100%> (ø)
src/interval.cpp 100% <100%> (ø)
src/nanotime.cpp 100% <100%> (ø)
inst/include/period.hpp 100% <100%> (ø)
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76b3881...4158607. Read the comment docs.

@eddelbuettel
Copy link
Owner

Massive indeed. I left some quick and simple comments. I will not claim to have read each line in each of the code lines. Let me run some tests...

ChangeLog Outdated

* .travis.yml: Load development version of RcppCCTZ from GitHub

2019-11-27 Leonardo Silvestri <lsilvestri@ztsdb.org>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More current date, maybe?

(Also, generally, ChangeLog is per "chunk" of changes, similar to git logs, maybe a a little more coarse. Here, it is of course a collection of a LOT of changes so may as well say so. Your code, your reference -- whatever feels rights.)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the date part, and added two header lines, see 18bc559

DESCRIPTION Outdated
Version: 0.2.4.2
Date: 2019-11-21
Version: 0.2.4.3
Date: 2019-11-28
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current date

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 18bc559

DESCRIPTION Show resolved Hide resolved

// The MIT License (MIT)
//
// Copyright (c) 2015, 2016 Howard Hinnant
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahhahhaa. I was wondering when I would have to give in an include his. He is unavoidable :) And good, this is now in C++20 as well.

(Should we farm it out to another package though to be more widely useable? Just a thought....)

inst/include/duration.hpp Show resolved Hide resolved
src/Makevars Outdated
## We want C++11
CXX_STD = CXX11
PKG_CXXFLAGS = -I../inst/include
PKG_LIBS = -lstdc++ -ldl
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want/need those for PKG_LIBS. They should be added automatically.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 18bc559

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent.

src/duration.cpp Outdated


RcppExport SEXP duration_from_string(SEXP s) {
try {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do possibly one better here by still relying on // [[Rcpp::export]] to get automatic type conversion AND the try/catch wrapper. One trick is to use // [[Rcpp::export(.duration_from_string)]] which does all the work for us, but still does not make the function 'public' in the "need a manual page for it too" sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, great, didn't know that. That is better and safer. Will take a look at that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed on-line, I ran into a brick wall trying to implement this in a test case. Which is puzzling, but enough to put this off for now. Filed under 'mysteries happening once S4 classes enter'. Works fine in simpler packages.

++s;
if (s + 5 > e || !isdigit(s[0]) || !isdigit(s[1]) ||
s[2] != ':' || !isdigit(s[3]) || !isdigit(s[4])) {
throw std::range_error("cannot parse nanoduration");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering whether this file should

  • get a try/catch block it currently does not have
  • use Rcpp::stop() instead of throw

The preference for Rcpp::stop() would apply to the other files too, of course.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. This is a low level function with no call to any of the R interface and when it is called it is protected by a try/catch block in RcppExport SEXP duration_from_string(SEXP s). You could see it as a library function and like the STL functions, it can throw. But one has to believe the exception mechanism will handle things correctly or else one would never use any C++: more specifically, after the catch in duration_from_string we have to be in a correct state or else C++ is broken (and we're not in a weird case like throwing from inside a constructor with partially allocated stuff).

On the other hand, I'm not sure of the subtleties before returning to R. So maybe Rcpp::stop should replace the forward_exception_to_r? I will look into the source code of Rcpp::stop to see what it's doing and get a better feel for some of the issues we could encounter. We could certainly replace all the forward_expection_to_r if Rcpp::stop is better.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's complicated. You and I know the code will only be called from out try/catch. But as it stands, it is a naked throw. Which is a minor smell. But heck, as we said, "we know" and we could just add a line of documentation.

As for the Rcpp::stop() -- I tend to use it everywhere (when Rcpp is used) instead of a plain throw because it has some associated code with it that should generally be beneficial and not impose cost. Call it style preference. Effectively the difference may not matter. Just how I tend to indent C/C++/R code by four spaces but everybody using RStudio comes at me with two spaces. Oh well :)

@eddelbuettel eddelbuettel merged commit 8046bb8 into master Mar 23, 2020
@eddelbuettel eddelbuettel deleted the feature/temporal_types branch March 25, 2020 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants