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

pmap discards attributes #251

Closed
kendonB opened this issue Sep 27, 2016 · 7 comments
Closed

pmap discards attributes #251

kendonB opened this issue Sep 27, 2016 · 7 comments

Comments

@kendonB
Copy link

kendonB commented Sep 27, 2016

Is this a feature or a bug?

seq(as.Date("1990-01-01"),
    as.Date("1990-01-02"), by = "days") %>% 
  list() %>% 
  purrr::pmap(function(x){
    print(class(x))
  })
# [1] "numeric"
# [1] "numeric"
# [[1]]
# [1] "numeric"
# 
# [[2]]
# [1] "numeric"

purrr::map yields a date object.

@picasa
Copy link

picasa commented Oct 18, 2016

Apparently, it's the same for POSIXct class.

library(lubridate)
library(dplyr)
library(purrr)

# data frame containing model inputs
inputs <- data_frame(a=1, t0=ymd("2016-10-12"))

# simplified model function
model <- function(t0, ...) {return(data_frame(time=format(t0, format="%d/%m")))}

# direct call to model fonction : time is the expected character string
model(t0=ymd("2016-10-12"))$time

# wished call to model function : time is a numeric value encoded in character string
inputs %>% pmap_df(., model) %>% .$time

@lionel-
Copy link
Member

lionel- commented Oct 18, 2016

It's a known non-feature that we will resolve with the vctrs package (we need C-level methods for joining vectors).

@lionel- lionel- changed the title pmap turns Dates into numerics pmap discards attributes Oct 18, 2016
@shrektan
Copy link

bite by this issue as well...

@hadley hadley closed this as completed Mar 3, 2017
@hadley
Copy link
Member

hadley commented Mar 3, 2017

This is a complicated issue and the root cause is not within purrr. We are aware of the problem and working to fix it in the long-term.

@Ax3man
Copy link

Ax3man commented May 24, 2017

Factors are also coerced to numeric:

pmap(list(1:5, factor(letters)[1:5]), paste)

@Deleetdk
Copy link

Deleetdk commented Feb 23, 2018

Issue still here as of purrr 0.2.4, at least for factors being converted to integers instead of the more obvious character alternative.

@yutannihilation
Copy link
Member

@Deleetdk FYI: the further discussion continues here.
#358 (comment)

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

8 participants