{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/haven/issues/179","repository_url":"https://api.github.com/repos/hadley/haven","labels_url":"https://api.github.com/repos/hadley/haven/issues/179/labels{/name}","comments_url":"https://api.github.com/repos/hadley/haven/issues/179/comments","events_url":"https://api.github.com/repos/hadley/haven/issues/179/events","html_url":"https://github.com/hadley/haven/pull/179","id":159116644,"number":179,"title":"Fix for #172 (labels) and #177 (variable label). ","user":{"login":"itsdalmo","id":6603877,"avatar_url":"https://avatars.githubusercontent.com/u/6603877?v=3","gravatar_id":"","url":"https://api.github.com/users/itsdalmo","html_url":"https://github.com/itsdalmo","followers_url":"https://api.github.com/users/itsdalmo/followers","following_url":"https://api.github.com/users/itsdalmo/following{/other_user}","gists_url":"https://api.github.com/users/itsdalmo/gists{/gist_id}","starred_url":"https://api.github.com/users/itsdalmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/itsdalmo/subscriptions","organizations_url":"https://api.github.com/users/itsdalmo/orgs","repos_url":"https://api.github.com/users/itsdalmo/repos","events_url":"https://api.github.com/users/itsdalmo/events{/privacy}","received_events_url":"https://api.github.com/users/itsdalmo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-06-08T09:19:03Z","updated_at":"2016-06-09T20:49:37Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/hadley/haven/pulls/179","html_url":"https://github.com/hadley/haven/pull/179","diff_url":"https://github.com/hadley/haven/pull/179.diff","patch_url":"https://github.com/hadley/haven/pull/179.patch"},"body":"This is a fix for:\r\n\r\n#### #172 \r\n`as_factor.labelled` should always keep predefined labels, even if they have no observations in the data (implicit missing). As discussed, the resulting levels should be sorted by values if `x` is a numeric vector, this satisfies your example:\r\n\r\n```R\r\nlikert <- labelled(sample(5, 100, replace = TRUE), c(\"Very Good\" = 1, \"Very Bad\" = 5))\r\nas_factor(likert)\r\n# > ...\r\n# > Levels: Very Good 2 3 4 Very Bad\r\n```\r\n\r\nAnd mine (current version of `as_factor` would sort levels alphabetically):\r\n```R\r\nlabs <- c(\"Agree\", \"Neutral\", \"Disagree\")\r\nsemant <- labelled(c(\"Neutral\", \"Agree\", \"Don't know\"), setNames(labs, labs))\r\nas_factor(semant)\r\n#> ...\r\n#> Levels: Agree Neutral Disagree Don't know\r\n```\r\n\r\n#### #177 \r\nas_factor should preserve the variable label. I'm thinking this should be done for **all** `as_factor` methods, and not just for `labelled` (since any type of vector can have a label).\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/hadley/haven/issues/comments/225021999","html_url":"https://github.com/hadley/haven/pull/179#issuecomment-225021999","issue_url":"https://api.github.com/repos/hadley/haven/issues/179","id":225021999,"user":{"login":"hadley","id":4196,"avatar_url":"https://avatars.githubusercontent.com/u/4196?v=3","gravatar_id":"","url":"https://api.github.com/users/hadley","html_url":"https://github.com/hadley","followers_url":"https://api.github.com/users/hadley/followers","following_url":"https://api.github.com/users/hadley/following{/other_user}","gists_url":"https://api.github.com/users/hadley/gists{/gist_id}","starred_url":"https://api.github.com/users/hadley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hadley/subscriptions","organizations_url":"https://api.github.com/users/hadley/orgs","repos_url":"https://api.github.com/users/hadley/repos","events_url":"https://api.github.com/users/hadley/events{/privacy}","received_events_url":"https://api.github.com/users/hadley/received_events","type":"User","site_admin":false},"created_at":"2016-06-09T20:49:37Z","updated_at":"2016-06-09T20:49:37Z","body":"Perfect - thanks!"}}
{"actor":{"display_login":"hadley"}}