{"action":"created","issue":{"url":"https://api.github.com/repos/tidyverse/forcats/issues/129","repository_url":"https://api.github.com/repos/tidyverse/forcats","labels_url":"https://api.github.com/repos/tidyverse/forcats/issues/129/labels{/name}","comments_url":"https://api.github.com/repos/tidyverse/forcats/issues/129/comments","events_url":"https://api.github.com/repos/tidyverse/forcats/issues/129/events","html_url":"https://github.com/tidyverse/forcats/issues/129","id":321157725,"number":129,"title":"allow `fct_inorder()` to tolerate `NA`s","user":{"login":"corybrunson","id":7768027,"avatar_url":"https://avatars1.githubusercontent.com/u/7768027?v=4","gravatar_id":"","url":"https://api.github.com/users/corybrunson","html_url":"https://github.com/corybrunson","followers_url":"https://api.github.com/users/corybrunson/followers","following_url":"https://api.github.com/users/corybrunson/following{/other_user}","gists_url":"https://api.github.com/users/corybrunson/gists{/gist_id}","starred_url":"https://api.github.com/users/corybrunson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/corybrunson/subscriptions","organizations_url":"https://api.github.com/users/corybrunson/orgs","repos_url":"https://api.github.com/users/corybrunson/repos","events_url":"https://api.github.com/users/corybrunson/events{/privacy}","received_events_url":"https://api.github.com/users/corybrunson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-05-08T12:02:25Z","updated_at":"2018-05-08T12:36:36Z","closed_at":null,"author_association":"NONE","body":"`fct_inorder()` throws an error when a character vector, or even a factor, contains missing values. This occurs at the `length(idx) != nlevels(f)` stop criterion in `lvls_reorder()`.\r\n\r\nThis behavior might be justified by the uncertainty of the \"true\" order due to the missing values, but missingness also imposes uncertainty on the frequency of factor levels, and `fct_infreq()` is not sensitive to `NA`s in the same way.\r\n\r\nSince factor variables often have missing values, it makes more sense to me not to require an additional step to put a factor with missing values in order. I'm sorry if this has been addressed elsewhere; i didn't find any mention in the previous issues.\r\n\r\nThanks for any feedback! If this sounds to others like a reasonable change, i can try a fix and submit a PR.\r\n\r\n``` r\r\nlibrary(forcats)\r\n\r\nfct_inorder(letters)\r\n#>  [1] a b c d e f g h i j k l m n o p q r s t u v w x y z\r\n#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z\r\nfct_inorder(c(letters, NA))\r\n#> Error: `idx` must contain one integer for each level of `f`\r\nfct_inorder(as.factor(c(letters, NA)))\r\n#> Error: `idx` must contain one integer for each level of `f`\r\n\r\nlvls_reorder(letters, 1:26)\r\n#>  [1] a b c d e f g h i j k l m n o p q r s t u v w x y z\r\n#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z\r\nlvls_reorder(letters, c(1:26, NA))\r\n#> Error: `idx` must contain one integer for each level of `f`\r\n\r\nfct_infreq(c(letters, NA))\r\n#>  [1] a    b    c    d    e    f    g    h    i    j    k    l    m    n   \r\n#> [15] o    p    q    r    s    t    u    v    w    x    y    z    <NA>\r\n#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/tidyverse/forcats/issues/comments/387387772","html_url":"https://github.com/tidyverse/forcats/issues/129#issuecomment-387387772","issue_url":"https://api.github.com/repos/tidyverse/forcats/issues/129","id":387387772,"user":{"login":"corybrunson","id":7768027,"avatar_url":"https://avatars1.githubusercontent.com/u/7768027?v=4","gravatar_id":"","url":"https://api.github.com/users/corybrunson","html_url":"https://github.com/corybrunson","followers_url":"https://api.github.com/users/corybrunson/followers","following_url":"https://api.github.com/users/corybrunson/following{/other_user}","gists_url":"https://api.github.com/users/corybrunson/gists{/gist_id}","starred_url":"https://api.github.com/users/corybrunson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/corybrunson/subscriptions","organizations_url":"https://api.github.com/users/corybrunson/orgs","repos_url":"https://api.github.com/users/corybrunson/repos","events_url":"https://api.github.com/users/corybrunson/events{/privacy}","received_events_url":"https://api.github.com/users/corybrunson/received_events","type":"User","site_admin":false},"created_at":"2018-05-08T12:36:36Z","updated_at":"2018-05-08T12:36:36Z","author_association":"NONE","body":"Oh, thank you, and pardon me! I didn't check the development code."}}
{"actor":{"display_login":"corybrunson"}}