{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/readr/issues/189","labels_url":"https://api.github.com/repos/hadley/readr/issues/189/labels{/name}","comments_url":"https://api.github.com/repos/hadley/readr/issues/189/comments","events_url":"https://api.github.com/repos/hadley/readr/issues/189/events","html_url":"https://github.com/hadley/readr/issues/189","id":86779929,"number":189,"title":"Handle also when header and data rows have different number of columns","user":{"login":"HenrikBengtsson","id":1616850,"avatar_url":"https://avatars.githubusercontent.com/u/1616850?v=3","gravatar_id":"","url":"https://api.github.com/users/HenrikBengtsson","html_url":"https://github.com/HenrikBengtsson","followers_url":"https://api.github.com/users/HenrikBengtsson/followers","following_url":"https://api.github.com/users/HenrikBengtsson/following{/other_user}","gists_url":"https://api.github.com/users/HenrikBengtsson/gists{/gist_id}","starred_url":"https://api.github.com/users/HenrikBengtsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HenrikBengtsson/subscriptions","organizations_url":"https://api.github.com/users/HenrikBengtsson/orgs","repos_url":"https://api.github.com/users/HenrikBengtsson/repos","events_url":"https://api.github.com/users/HenrikBengtsson/events{/privacy}","received_events_url":"https://api.github.com/users/HenrikBengtsson/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-06-10T00:21:08Z","updated_at":"2015-09-03T21:40:33Z","closed_at":null,"body":"# Case 1: More column names than data columns\r\n`read.table()` has `fill=TRUE` to handle the case for when there are more column names than columns in the data rows, e.g.\r\n```r\r\n> read_tsv(\"a\\tb\\tc\\n1\\t2\\n\")\r\nError: You have 3 column names, but 2 columns\r\n\r\n> read.table(text=\"a\\tb\\tc\\n1\\t2\\n\", fill=FALSE)\r\nError in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,\r\n  line 2 did not have 3 elements\r\n> read.table(text=\"a\\tb\\tc\\n1\\t2\\n\", fill=TRUE)\r\n  V1 V2 V3\r\n1  a  b  c\r\n2  1  2\r\n```\r\nLooking at the help, I don't think there is way to use `read_tsv()` to deal with this case.\r\n\r\nWISH: Make it possible \"fill\" _data rows_ with empty values/NAs, when data rows lack trailing cells.  This would assume the missing ones are at the end, cf. argument `fill` of `read.table()`.\r\n\r\n# Case 2: Fewer column names than data columns\r\n`read.table()` does not handle this.  I don't think `read_tsv()` does either.\r\n```r\r\n> read.table(text=\"a\\tb\\n1\\t2\\t3\\t4\\n\", header=TRUE, fill=FALSE)\r\nError in read.table(text = \"a\\tb\\n1\\t2\\t3\\t4\\n\", header = TRUE, fill = FALSE) :\r\n  more columns than column names\r\n> read.table(text=\"a\\tb\\n1\\t2\\t3\\t4\\n\", header=TRUE, fill=TRUE)\r\nError in read.table(text = \"a\\tb\\n1\\t2\\t3\\t4\\n\", header = TRUE, fill = FALSE) :\r\n  more columns than column names\r\n> read_tsv(\"a\\tb\\n1\\t2\\t3\\t4\\n\")\r\nError: You have 2 column names, but 4 columns\r\n```\r\n\r\nWISH: Make it possible \"fill\" _column names_ with empty values/NAs, when header lack trailing column names.  This would assume the missing ones are at the end, cf. argument `fill` of `read.table()`.\r\n\r\n## Background\r\nFor a real-world example, please see https://gist.github.com/HenrikBengtsson/dabc383aaa958c0ed49a.  The above examples are never ending stories in my life.\r\n\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/hadley/readr/issues/comments/137581877","html_url":"https://github.com/hadley/readr/issues/189#issuecomment-137581877","issue_url":"https://api.github.com/repos/hadley/readr/issues/189","id":137581877,"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":"2015-09-03T21:40:33Z","updated_at":"2015-09-03T21:40:33Z","body":"How does this look?\r\n\r\n``` r\r\nread_csv(col_types = \"ii\", \"a,b\\n1\")\r\n#>   a  b\r\n#> 1 1 NA\r\nread_csv(col_types = \"ii\", \"a,b\\n1,2,3\")\r\n#> Warning: 1 problems parsing literal data. See problems(...) for more\r\n#> details.\r\n#>   a b\r\n#> 1 1 2\r\n\r\nread_csv(\"a,b\\n1\")\r\n#>   a\r\n#> 1 1\r\nread_csv(\"a,b\\n1,2,3\")\r\n#>   a b X3\r\n#> 1 1 2  3\r\n```\r\n\r\nI guess they probably should all generate warnings :/"}}