[Rcpp-devel] bug with DatetimeVector ?
Dirk Eddelbuettel
edd at debian.org
Fri Jul 19 14:32:01 CEST 2013
On 19 July 2013 at 14:05, stat quant wrote:
| Hello list, I might have found a bug, would you mind checking it too?
No, you didn't. See below.
| In R:
|
| library("Rcpp")
| sourceCpp("rcpp.cpp")
| df = data.frame(x=c(1L,NA,2L), dt=as.POSIXct(c(1L,NA,2L),origin='1970-01-01'))
|
| df
| x dt
| 1 1 1970-01-01 00:00:01
| 2 NA <NA>
| 3 2 1970-01-01 00:00:02
|
| In C++
|
| //[[Rcpp::export]]
| void bug(DataFrame df){
| DatetimeVector dt = df["dt"];
| }
That __obviously__ does not compile (no header, no namespace, ...) so I think
you are being sloppy.
Execution of a __repaired and reproducible__ example, first via littler then
via R:
edd at don:~$ r -lRcpp -e'sourceCpp("/tmp/statquant.cpp")'
> df <- data.frame(x=c(1L,NA,2L),
+ dt=as.POSIXct(c(1L,NA,2L),origin='1970-01-01'))
> print(df)
x dt
1 1 1969-12-31 18:00:01
2 NA <NA>
3 2 1969-12-31 18:00:02
> bug(df)
> cat("Hello world\n")
Hello world
edd at don:~$ R -q -e 'Rcpp::sourceCpp("/tmp/statquant.cpp")'
R> Rcpp::sourceCpp("/tmp/statquant.cpp")
R> df <- data.frame(x = c(1, NA, 2), dt = as.POSIXct(c(1,
+ NA, 2), origin = "1970-01-01"))
R> print(df)
x dt
1 1 1969-12-31 18:00:01
2 NA <NA>
3 2 1969-12-31 18:00:02
R> bug(df)
R> cat("Hello world\n")
Hello world
R>
R>
edd at don:~$
A complete cpp snippet follows below. Please construct better examples that
actually __work__ next time, test them on __fresh sessions__ and consider
including the R test code in the C++ snippet as I do here. Oh, and stop
using the hidous '=' for assignment in R ;-)
Dirk
-----------------------------------------------------------------------------
#include <Rcpp.h>
using namespace Rcpp;
//[[Rcpp::export]]
void bug(DataFrame df){
DatetimeVector dt = df["dt"];
}
/*** R
df <- data.frame(x=c(1L,NA,2L),
dt=as.POSIXct(c(1L,NA,2L),origin='1970-01-01'))
print(df)
bug(df)
cat("Hello world\n")
*/
-----------------------------------------------------------------------------
|
| Executing bug(df) in R crashes the R session on my box
|
| sessionInfo()
| R version 3.0.0 (2013-04-03)
| Platform: x86_64-w64-mingw32/x64 (64-bit)
| locale:
| [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252
| LC_MONETARY=French_France.1252 LC_NUMERIC=C
| LC_TIME=C
| attached base packages:
| [1] stats graphics grDevices datasets utils methods base
|
| other attached packages:
| [1] Rcpp_0.10.4 vimcom_0.9-8
| loaded via a namespace (and not attached):
| [1] tools_3.0.0
|
| Regards
|
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list