mutate_ and lubridate::parse_date_time SE not working together as expected

27 views
Skip to first unread message

Manny A

unread,
Mar 10, 2016, 10:52:36 PM3/10/16
to manipulatr

Consider:
``` R
df <- frame_data( ~ start_date,
                    "07/15/2015 15:39",
                    "07/15/2015 15:42")

df_NSE <- df %>%
          mutate(response_date = parse_date_time(start_date, orders ="mdY hm"))
```

I would have thought that something like the following would be a standard-evaluation equivalent:
``` R
var_name <- "start_date"
df_SE_expected_to_work <- df %>%
          mutate_(response_date = ~parse_date_time(var_name, orders ="mdY hm"))
```
but this just throws a warning and just has blank rows for the response_date column:
```R
Warning message:
All formats failed to parse. No formats found.
```
I tried many variations even with interp, just to make sure it wasnt my understanding of NSE such as this one:
``` R
df_SE_interp_expected_to_work <- df %>%
          mutate_(response_date = interp(~parse_date_time(var_name, orders ="mdY hm"), var_name = var_name))
```
but i get the same outcome

I was able to hack a working solution for both cases:
``` R
df_SE_working <- df %>%
          mutate_(response_date = ~parse_date_time(df[[var_name]], orders ="mdY hm"))
df_SE_interp_working <- df %>%
          mutate_(response_date = interp(~parse_date_time(df[[var_name]], orders ="mdY hm"), var_name = var_name))
```

```R
sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.4 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8   
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C      

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

other attached packages:
 [1] lazyeval_0.1.10.9000 lubridate_1.5.0      ednaetl_0.1          purrr_0.2.0          psqlfun_0.1        
 [6] dplyr_0.4.3.9000     tidyr_0.4.0          uuid_0.1-2           RPostgreSQL_0.4      DBI_0.3.1          

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.3        assertthat_0.1     R6_2.1.2           magrittr_1.5       stringi_1.0-1    
 [6] tools_3.2.3        stringr_1.0.0      yaml_2.1.13        parallel_3.2.3     rsconnect_0.4.1.11
[11] knitr_1.12.3    
```
Maybe I'm just missing something obvious?
Reply all
Reply to author
Forward
0 new messages