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

Rcpp_0.12.14 - error when using Rcpp::is_na() on newDateVector #781

Closed
shrektan opened this Issue Dec 1, 2017 · 12 comments

Comments

Projects
None yet
2 participants
@shrektan

shrektan commented Dec 1, 2017

After upgrading to 0.12.14, Rcpp::is_na() can't be used on newDateVector any more. Here is the minimal reproducible example, my session info and the error message.

miminal example

It works fine on Rcpp 0.12.13 but not on 0.12.14.

Rcpp::cppFunction("
bool any_na_date(newDateVector dates) {
return any(is_na(dates));
}")

sessionInfo()

R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.2

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] zh_CN.UTF-8/zh_CN.UTF-8/zh_CN.UTF-8/C/zh_CN.UTF-8/zh_CN.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.4.2 tools_3.4.2    yaml_2.1.14    Rcpp_0.12.14  

Error message

In file included from file1ba335704213.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include/Rcpp.h:74:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include/Rcpp/sugar/sugar.h:31:
In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include/Rcpp/sugar/functions/functions.h:36:
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include/Rcpp/sugar/functions/is_na.h:75:25: error: member reference base type 'const typename storage_type<14>::type' (aka 'const double') is not a structure or union
           return ref[i].is_na() ;
                  ~~~~~~^~~~~~
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include/Rcpp/vector/VectorBase.h:46:47: note: in instantiation of member function 'Rcpp::sugar::IsNa_Vector_is_na<Rcpp::newDateVector>::operator[]' requested here
            return static_cast<const VECTOR*>(this)->operator[](i) ;
                                                     ^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include/Rcpp/sugar/functions/any.h:68:8: note: in instantiation of member function 'Rcpp::VectorBase<10, false, Rcpp::sugar::IsNa_Vector_is_na<Rcpp::newDateVector> >::operator[]' requested here
                        if( object[i] == TRUE ) {
                            ^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include/Rcpp/sugar/logical/SingleLogicalResult.h:50:27: note: in instantiation of member function 'Rcpp::sugar::Any<false, Rcpp::sugar::IsNa_Vector_is_na<Rcpp::newDateVector> >::apply' requested here
                        static_cast<T&>(*this).apply() ;
                                               ^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include/Rcpp/sugar/logical/SingleLogicalResult.h:55:3: note: in instantiation of member function 'Rcpp::sugar::SingleLogicalResult<false, Rcpp::sugar::Any<false, Rcpp::sugar::IsNa_Vector_is_na<Rcpp::newDateVector> > >::apply' requested here
                apply() ;
                ^
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include/Rcpp/sugar/logical/SingleLogicalResult.h:76:10: note: in instantiation of member function 'Rcpp::sugar::SingleLogicalResult<false, Rcpp::sugar::Any<false, Rcpp::sugar::IsNa_Vector_is_na<Rcpp::newDateVector> > >::is_true' requested here
                return is_true() ;
                       ^
file1ba335704213.cpp:8:8: note: in instantiation of member function 'Rcpp::sugar::SingleLogicalResult<false, Rcpp::sugar::Any<false, Rcpp::sugar::IsNa_Vector_is_na<Rcpp::newDateVector> > >::operator bool' requested here
return any(is_na(dates));
       ^
1 error generated.
make: *** [file1ba335704213.o] Error 1
clang++  -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" -I"/private/var/folders/55/f_cnh9dd40b4lb_6yqzmts8h0000gp/T/RtmpIDkyUL/sourceCpp-x86_64-apple-darwin15.6.0-0.12.14" -I/usr/local/include   -fPIC  -Wall -g -O2  -c file1ba335704213.cpp -o file1ba335704213.o
Error in sourceCpp(code = code, env = env, rebuild = rebuild, cacheDir = cacheDir,  : 
  Error 1 occurred building shared library.
@eddelbuettel

This comment has been minimized.

Member

eddelbuettel commented Dec 1, 2017

Will take a look.

For the record, you had newDatevector since November of last year. The change in 0.12.14 is merely that Datevector now defaults to it. You can get the old one back as documented.

@eddelbuettel

This comment has been minimized.

Member

eddelbuettel commented Dec 1, 2017

Dirty hack:

R> cppFunction("bool any_na_date(NumericVector dates) { return any(is_na(dates)); }")
R> any_na_date(Sys.Date() + 0:3)
[1] FALSE
R> any_na_date(c(Sys.Date() + 0:3, NA))
[1] TRUE
R> 

We probably just need to give the compiler a hand over on the various trait types...

@shrektan

This comment has been minimized.

shrektan commented Dec 1, 2017

Well yes, I know 0.12.14 update is just typedef the DateVector to newDateVector...
I tried to file a PR but found the solution is not that obvious to me... 😢
So I have to ask you for help... 😿
Thanks.

@eddelbuettel

This comment has been minimized.

Member

eddelbuettel commented Dec 1, 2017

Yes, template logic is tricky. Here is slightly less hacky answer, still explicity defering to the underlying NumericVector:

cppFunction("bool any_na_date(DateVector d) { return any(is_na(NumericVector(d))); }")
@shrektan

This comment has been minimized.

shrektan commented Dec 1, 2017

Thanks for the hacky workaround.

@shrektan

This comment has been minimized.

shrektan commented Dec 1, 2017

Something that I can't understand is 0.12.14 only typedefs DateVector to newDateVector instead of oldDateVector. It should have no impact on the newDateVector's use at all 😓 It's really tricky...

@eddelbuettel

This comment has been minimized.

Member

eddelbuettel commented Dec 1, 2017

Beforehand DateVector was oldDateVector .... In essence, I don't know your are asking. I used shorthand, if you insist you can do the hacky fix as

R> cppFunction("bool any_na_date(newDateVector d) { return any(is_na(NumericVector(d))); }")
R> 
@shrektan

This comment has been minimized.

shrektan commented Dec 1, 2017

The hacky fix is already good for me.

What I'm asking is:

  • is_na() works fine on newDateVector in 0.12.13.
  • 0.12.14 doesn't change anything on newDateVector.

Suddenly, is_na() doesn't work on newDateVector in 0.12.14 any more, why?

@eddelbuettel

This comment has been minimized.

Member

eddelbuettel commented Dec 1, 2017

Some Datevector related code was resolving to what is oldDateVector up until 0.12.13 and now resolves to newDateVector. There must be an unintended consequence and side effect involving just Datevector now.

@shrektan

This comment has been minimized.

shrektan commented Dec 1, 2017

Get it. Thanks!

eddelbuettel added a commit that referenced this issue Dec 3, 2017

@eddelbuettel

This comment has been minimized.

Member

eddelbuettel commented Dec 4, 2017

Thanks again for the report. Whatt is now in master as Rcpp 0.12.14.3 should help you.

@shrektan

This comment has been minimized.

shrektan commented Dec 4, 2017

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment