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

Dates before the epoch cause R to crash #12

Closed
FarrelBuch opened this issue Oct 7, 2016 · 8 comments
Closed

Dates before the epoch cause R to crash #12

FarrelBuch opened this issue Oct 7, 2016 · 8 comments

Comments

@FarrelBuch
Copy link

In my data set I had a date of birth that was before January 1, 1970. It crashed Rstudio and R. It took me a long time to find out what was going on.

I don't really know what an epoch is in software but I know that anytime can't handle <1970-01-01

library (anytime)  
anydate("10/20/1970")
anydate("01/01/1970")
anydate("12/01/1969")

The first two work as expected. The last line crashes R

@eddelbuettel
Copy link
Owner

Thanks, I'll look into that.

@eddelbuettel
Copy link
Owner

What is your OS? On Linux, I get

edd@max:~$ r -l anytime -p -e 'anydate(c("10/20/1970", "01/01/1970", "12/01/1969", "12/13/2014"))'
[1] "1970-10-20" "1970-01-01" "1969-12-01" "2014-12-13"
edd@max:~$ 
edd@max:~$ Rscript -e 'library(anytime); anydate(c("10/20/1970", "01/01/1970", "12/01/1969", "12/13/2014"))'
[1] "1970-10-20" "1970-01-01" "1969-12-01" "2014-12-13"
edd@max:~$ 

@FarrelBuch
Copy link
Author

Windows 8

On Fri, Oct 7, 2016, 20:35 Dirk Eddelbuettel notifications@github.com
wrote:

What is your OS? On Linux, I get

edd@max:$ r -l anytime -p -e 'anydate(c("10/20/1970", "01/01/1970", "12/01/1969", "12/13/2014"))'
[1] "1970-10-20" "1970-01-01" "1969-12-01" "2014-12-13"
edd@max:
$
edd@max:$ Rscript -e 'library(anytime); anydate(c("10/20/1970", "01/01/1970", "12/01/1969", "12/13/2014"))'
[1] "1970-10-20" "1970-01-01" "1969-12-01" "2014-12-13"
edd@max:
$


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#12 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AB7gyeodopEwiCAeJpXI6THRRKVjfeY6ks5qxuU5gaJpZM4KRfNd
.

Farrel Buchinsky
(412) 567-7870 (gets me everywhere)

@eddelbuettel
Copy link
Owner

Can you build from source, ie test the GitHub version? It has a simpler test function:

R> library(anytime)
R> anytime:::testFormat("%m/%d/%Y", "12/01/1969")
[1] "1969-12-01 CST"
R> as.numeric(anytime:::testFormat("%m/%d/%Y", "12/01/1969"))
[1] -2656800
R> 

We could add some print statements to see what is going on there.

@FarrelBuch
Copy link
Author

Yes, I will try to do that. In the meantime, I tried these statements in Rgui on my computer at home which is running the most recent version of Windows 10 Pro (10.0.14393 build 14393)

> library(anytime)
> anydate("2/18/2003")
[1] "2003-02-18"
> anydate("1/1/1970")
[1] NA
> anydate("1/2/1970")
[1] NA
> anydate("1/2/1971")
[1] NA
> anydate("1/13/1971")
[1] "1971-01-13"
> anydate("1/13/1970")
[1] "1970-01-13"
> anydate("1/12/1970")
[1] "1970-01-12"
> anydate("1/11/1970")
[1] "1970-01-11"
> anydate("1/10/1970")
[1] "1970-01-10"
> anydate("1/9/1970")
[1] NA
> anydate("1/19/1970")
[1] "1970-01-19"
> getRversion()
[1] ‘3.3.1’

anydate("1/19/1969") crashed the program

@FarrelBuch
Copy link
Author

OK. I built from source

I still get the crash.
I tried anytime:::testFormat("%m/%d/%Y", "12/01/1969") and it too resulted in "R Session Aborted"

Here is my console output to demonstrate that I did what I think I did.

> library(devtools)
> devtools::install_github("eddelbuettel/anytime")
Downloading GitHub repo eddelbuettel/anytime@master
from URL https://api.github.com/repos/eddelbuettel/anytime/zipball/master
Installing anytime
"C:/PROGRA~1/R/R-33~1.1/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL  \
  "C:/Users********AppData/Local/Temp/Rtmpsv6DVB/devtools393814996c3a/eddelbuettel-anytime-c87d743" --library="G:/Farrel  \
  Data/Documents/R/win-library/3.3" --install-tests 

* installing *source* package 'anytime' ...
** libs

*** arch - i386
c:/Rtools/mingw_32/bin/g++  -I"C:/PROGRA~1/R/R-33~1.1/include" -DNDEBUG    -I"G:*********Documents/R/win-library/3.3/Rcpp/include" -I"G*********Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
c:/Rtools/mingw_32/bin/g++  -I"C:/PROGRA~1/R/R-33~1.1/include" -DNDEBUG    -I"G**********Documents/R/win-library/3.3/Rcpp/include" -I"G***********Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c anytime.cpp -o anytime.o
c:/Rtools/mingw_32/bin/g++ -shared -s -static-libgcc -o anytime.dll tmp.def RcppExports.o anytime.o -Ld:/Compiler/gcc-4.9.3/local330/lib/i386 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-33~1.1/bin/i386 -lR
installing to G**********Documents/R/win-library/3.3/anytime/libs/i386

*** arch - x64
c:/Rtools/mingw_64/bin/g++  -I"C:/PROGRA~1/R/R-33~1.1/include" -DNDEBUG    -I"G***********Documents/R/win-library/3.3/Rcpp/include" -I"G*********************Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
c:/Rtools/mingw_64/bin/g++  -I"C:/PROGRA~1/R/R-33~1.1/include" -DNDEBUG    -I"G******************Documents/R/win-library/3.3/Rcpp/include" -I"G****************Documents/R/win-library/3.3/BH/include" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c anytime.cpp -o anytime.o
c:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o anytime.dll tmp.def RcppExports.o anytime.o -Ld:/Compiler/gcc-4.9.3/local330/lib/x64 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-33~1.1/bin/x64 -lR
installing to G**************Documents/R/win-library/3.3/anytime/libs/x64
** R
** inst
** tests
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* DONE (anytime)
> library(anytime)
> anydate("2/18/2003")
[1] "2003-02-18"
> anydate("1/1/1970")
[1] NA
> anydate("1/2/1970")
[1] NA
> anydate("1/2/1971")
[1] NA
> anydate("1/13/1971")
[1] "1971-01-13"
> anydate("1/13/1970")
[1] "1970-01-13"
> anydate("1/12/1970")
[1] "1970-01-12"
> anydate("1/11/1970")
[1] "1970-01-11"
> anydate("1/10/1970")
[1] "1970-01-10"
> anydate("1/9/1970")
[1] NA
> anydate("1/19/1970")
[1] "1970-01-19"
> getRversion()
[1] ‘3.3.1’
> package_version(x = "anytime")
Error: invalid version specification ‘anytime’

And then when I entered anydate("1/19/1969") everything crashed.

Is there anyway I can help troubleshoot?

@eddelbuettel
Copy link
Owner

eddelbuettel commented Oct 9, 2016

Thank you for looking into this! I won't have access to my windows vw til Monday.

Yes, I think adding print statements along the way is a start. Something like this, maybe, in that function:

// [[Rcpp::export]]
Rcpp::NumericVector testFormat(const std::string fmt, const std::string s, const std::string tz = "") {

    bt::ptime pt, ptbase;

    std::istringstream is(s);
    std::locale loc = std::locale(std::locale::classic(), new bt::time_input_facet(fmt));

    Rprintf("before imbue\n");
    is.imbue(loc);
    Rprintf("before parse\n");
    is >> pt;
    Rprintf("after parse\n");

    double timeval = (pt == ptbase) ? NAN : ptToDouble(pt);

    Rcpp::NumericVector pv(1);
    pv(0) = timeval;
    pv.attr("class") = Rcpp::CharacterVector::create("POSIXct", "POSIXt");
    pv.attr("tzone") = tz;

    return pv;
}

(That would require replacing the function in git, so you'd need a tarball or zip of the current source first. If you'd rather use devtools from a branch I can commit this too.)

This is starting to look like an issue in Boost on Windows as we do little code here. Or it is a bug I am not seeing -- maybe the Rprintf() above will help. I suspect it is crashing in is >> pt when parsing the string.

@eddelbuettel
Copy link
Owner

I found the issue. This line does not work on Windows for dates before 1970 -- the tm_isdt access creates the segfault. Weird.

eddelbuettel added a commit that referenced this issue Oct 10, 2016
no tm_isdst on Windows before 1970 (closes #12)
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

No branches or pull requests

2 participants