{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/dplyr/issues/2256","repository_url":"https://api.github.com/repos/hadley/dplyr","labels_url":"https://api.github.com/repos/hadley/dplyr/issues/2256/labels{/name}","comments_url":"https://api.github.com/repos/hadley/dplyr/issues/2256/comments","events_url":"https://api.github.com/repos/hadley/dplyr/issues/2256/events","html_url":"https://github.com/hadley/dplyr/issues/2256","id":190103560,"number":2256,"title":"error when writing character fields containing NAs to mysql table","user":{"login":"eduardgrebe","id":613657,"avatar_url":"https://avatars.githubusercontent.com/u/613657?v=3","gravatar_id":"","url":"https://api.github.com/users/eduardgrebe","html_url":"https://github.com/eduardgrebe","followers_url":"https://api.github.com/users/eduardgrebe/followers","following_url":"https://api.github.com/users/eduardgrebe/following{/other_user}","gists_url":"https://api.github.com/users/eduardgrebe/gists{/gist_id}","starred_url":"https://api.github.com/users/eduardgrebe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eduardgrebe/subscriptions","organizations_url":"https://api.github.com/users/eduardgrebe/orgs","repos_url":"https://api.github.com/users/eduardgrebe/repos","events_url":"https://api.github.com/users/eduardgrebe/events{/privacy}","received_events_url":"https://api.github.com/users/eduardgrebe/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-17T16:57:53Z","updated_at":"2016-11-22T15:20:48Z","closed_at":null,"body":"I get the following error when trying to write a table to a mysql connection with copy_to():\r\n\r\n```\r\n> sanbs_db <- src_mysql(\"sanbs\", host = \"localhost\", user = \"root\")\r\n> results_diagnostic.db <- copy_to(sanbs_db, results_diagnostic, temporary = FALSE, indexes = list(c(\"result_id\",\"donation_id\")))\r\nError in if (n <= 65535) { : missing value where TRUE/FALSE needed\r\n```\r\n\r\nI believe the error occurs because I have true NAs in character fields, and the following check in src-mysql.r produces n=NA instead of the expected maximum length:\r\n\r\n```\r\ndb_data_type.MySQLConnection <- function(con, fields, ...) {\r\n  char_type <- function(x) {\r\n    n <- max(nchar(as.character(x), \"bytes\"))\r\n    if (n <= 65535) {\r\n      paste0(\"varchar(\", n, \")\")\r\n    } else {\r\n      \"mediumtext\"\r\n    }\r\n}\r\n```\r\n\r\nthe problem can be demonstrated with:\r\n\r\n```\r\n> stringvec <- c(\"a\",NA,\"bb\")\r\n> max(nchar(stringvec))\r\n[1] NA\r\n> max(na.omit(nchar(stringvec)))\r\n[1] 2\r\n```\r\n\r\nI'm not sure what this means for writing NULL values into the db table."},"comment":{"url":"https://api.github.com/repos/hadley/dplyr/issues/comments/262269011","html_url":"https://github.com/hadley/dplyr/issues/2256#issuecomment-262269011","issue_url":"https://api.github.com/repos/hadley/dplyr/issues/2256","id":262269011,"user":{"login":"krlmlr","id":1741643,"avatar_url":"https://avatars.githubusercontent.com/u/1741643?v=3","gravatar_id":"","url":"https://api.github.com/users/krlmlr","html_url":"https://github.com/krlmlr","followers_url":"https://api.github.com/users/krlmlr/followers","following_url":"https://api.github.com/users/krlmlr/following{/other_user}","gists_url":"https://api.github.com/users/krlmlr/gists{/gist_id}","starred_url":"https://api.github.com/users/krlmlr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krlmlr/subscriptions","organizations_url":"https://api.github.com/users/krlmlr/orgs","repos_url":"https://api.github.com/users/krlmlr/repos","events_url":"https://api.github.com/users/krlmlr/events{/privacy}","received_events_url":"https://api.github.com/users/krlmlr/received_events","type":"User","site_admin":false},"created_at":"2016-11-22T15:20:48Z","updated_at":"2016-11-22T15:20:48Z","body":"Thanks, confirmed. Would you like to contribute a test case and perhaps a fix?"}}
{"actor":{"display_login":"krlmlr"}}