Skip to content

Commit

Permalink
make it explicit that POSIXlt results are forbidden in mutate. closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Oct 13, 2014
1 parent 179032c commit da44c79
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -26,6 +26,8 @@
* Added class `JoinFactorFactorVisitor_SameLevels` for the special case when
two factors with the same levels (in the same order) are joined (#675).

* `mutate` forbids `POSIXlt` results (#670)

# dplyr 0.3.0.1

* Fixed problem with test script on Windows.
Expand Down
6 changes: 6 additions & 0 deletions inst/include/dplyr/Gatherer.h
Expand Up @@ -179,6 +179,9 @@ namespace dplyr {

template <typename Data, typename Subsets>
inline Gatherer* constant_gatherer(SEXP x, int n){
if( Rf_inherits(x, "POSIXlt" ) ){
stop("`mutate` does not support `POSIXlt` results");
}
switch( TYPEOF(x) ){
case INTSXP: {
if( Rf_inherits(x, "Date" )) return new ConstantTypedGatherer<INTSXP,Data,Subsets>(x,n, get_date_classes() ) ;
Expand All @@ -204,6 +207,9 @@ namespace dplyr {
typename Data::group_iterator git = gdf.group_begin() ;
SlicingIndex indices = *git ;
Shield<SEXP> first( proxy.get(indices) ) ;
if( Rf_inherits(first, "POSIXlt" ) ){
stop("`mutate` does not support `POSIXlt` results");
}
switch( TYPEOF(first) ){
case INTSXP:
{
Expand Down
3 changes: 3 additions & 0 deletions src/dplyr.cpp
Expand Up @@ -1889,6 +1889,9 @@ SEXP mutate_not_grouped(DataFrame df, const LazyDots& dots){

check_supported_type(result, name) ;

if( Rf_inherits(result, "POSIXlt") ){
stop("`mutate` does not support `POSIXlt` results");
}
if( Rf_length(result) == df.nrows() ){
// ok
} else if( Rf_length(result) == 1 ){
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-mutate.r
Expand Up @@ -320,3 +320,16 @@ test_that("mutate handles using and gathering complex data (#436)", {
expect_true( all(res$constant == 2+2i) )
})

test_that("mutate forbids POSIXlt results (#670)", {
expect_error(
data.frame(time='2014/01/01 10:10:10') %>% mutate(time=as.POSIXlt(time)),
"does not support"
)

expect_error(
data.frame(time='2014/01/01 10:10:10', a=2) %>% group_by(a) %>% mutate(time=as.POSIXlt(time)),
"does not support"
)

})

0 comments on commit da44c79

Please sign in to comment.