{"action":"created","issue":{"url":"https://api.github.com/repos/kbenoit/quanteda/issues/106","repository_url":"https://api.github.com/repos/kbenoit/quanteda","labels_url":"https://api.github.com/repos/kbenoit/quanteda/issues/106/labels{/name}","comments_url":"https://api.github.com/repos/kbenoit/quanteda/issues/106/comments","events_url":"https://api.github.com/repos/kbenoit/quanteda/issues/106/events","html_url":"https://github.com/kbenoit/quanteda/issues/106","id":136710231,"number":106,"title":"Subsetting on dates doesn't give error on integer","user":{"login":"tpaskhalis","id":2973437,"avatar_url":"https://avatars.githubusercontent.com/u/2973437?v=3","gravatar_id":"","url":"https://api.github.com/users/tpaskhalis","html_url":"https://github.com/tpaskhalis","followers_url":"https://api.github.com/users/tpaskhalis/followers","following_url":"https://api.github.com/users/tpaskhalis/following{/other_user}","gists_url":"https://api.github.com/users/tpaskhalis/gists{/gist_id}","starred_url":"https://api.github.com/users/tpaskhalis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tpaskhalis/subscriptions","organizations_url":"https://api.github.com/users/tpaskhalis/orgs","repos_url":"https://api.github.com/users/tpaskhalis/repos","events_url":"https://api.github.com/users/tpaskhalis/events{/privacy}","received_events_url":"https://api.github.com/users/tpaskhalis/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-26T14:17:17Z","updated_at":"2016-02-28T08:12:18Z","closed_at":"2016-02-28T08:12:18Z","body":"As some corpora contain metadata of class `Date`, `subset()` function allows selecting documents based on this information. The issue is that it accepts arguments of multiple classes, such as `Date`, `character` and `numeric`.  This makes it possible, by mistake, to supply an integer in the form `1980-01-01`, which leads to the actual subtraction, resulting in `1978`, which, in turn, is evaluated as a number of days since epoch, depending on the system.\r\n\r\nIt's difficult to tell whether it is expected behaviour or not. My main argument against this being normal behaviour is that the function `as.Date(1980-01-01)` returns an error, due to unspecified origin. While inside `subset()` it behaves as if origin is explicitly specified. But, strictly speaking, `Date` has type double. Honestly, my feeling is that we cannot do much about it, as this seems to be the behaviour of base R function `subset.data.frame`. Unless we can actually confirm that this is a bug in base R. So far, I couldn't find anything on Bugzilla.\r\n\r\n```\r\n> df <- data.frame(name = letters[1:10], \r\n+                  date = seq(as.Date(\"1976/1/1\"), as.Date(\"1985/1/1\"), \"years\"))\r\n> \r\n> subset(df, date > as.Date(\"1980/1/1\"))\r\n   name       date\r\n6     f 1981-01-01\r\n7     g 1982-01-01\r\n8     h 1983-01-01\r\n9     i 1984-01-01\r\n10    j 1985-01-01\r\n> subset(df, date > \"1980/1/1\")\r\n   name       date\r\n6     f 1981-01-01\r\n7     g 1982-01-01\r\n8     h 1983-01-01\r\n9     i 1984-01-01\r\n10    j 1985-01-01\r\n> subset(df, date > 1980/1/1)\r\n   name       date\r\n1     a 1976-01-01\r\n2     b 1977-01-01\r\n3     c 1978-01-01\r\n4     d 1979-01-01\r\n5     e 1980-01-01\r\n6     f 1981-01-01\r\n7     g 1982-01-01\r\n8     h 1983-01-01\r\n9     i 1984-01-01\r\n10    j 1985-01-01\r\n``` "},"comment":{"url":"https://api.github.com/repos/kbenoit/quanteda/issues/comments/189818149","html_url":"https://github.com/kbenoit/quanteda/issues/106#issuecomment-189818149","issue_url":"https://api.github.com/repos/kbenoit/quanteda/issues/106","id":189818149,"user":{"login":"kbenoit","id":2182246,"avatar_url":"https://avatars.githubusercontent.com/u/2182246?v=3","gravatar_id":"","url":"https://api.github.com/users/kbenoit","html_url":"https://github.com/kbenoit","followers_url":"https://api.github.com/users/kbenoit/followers","following_url":"https://api.github.com/users/kbenoit/following{/other_user}","gists_url":"https://api.github.com/users/kbenoit/gists{/gist_id}","starred_url":"https://api.github.com/users/kbenoit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kbenoit/subscriptions","organizations_url":"https://api.github.com/users/kbenoit/orgs","repos_url":"https://api.github.com/users/kbenoit/repos","events_url":"https://api.github.com/users/kbenoit/events{/privacy}","received_events_url":"https://api.github.com/users/kbenoit/received_events","type":"User","site_admin":false},"created_at":"2016-02-28T08:12:18Z","updated_at":"2016-02-28T08:12:18Z","body":"Not a bug - this is just how R evaluates expressions. `1980-01-01` is an arithmetic operation involving three numerics. `as.Date(\"1980/01/01\")` with the comparison operator `>` keeps the two quantities as dates, as does the properly formatted strings \"1980/01/01\" or \"1980-01-01\".\r\n\r\nSo `subset.corpus()` with dates works exactly the way `subset.data.frame()` works. It's not a bug, it's a feature!"}}