{"action":"created","issue":{"url":"https://api.github.com/repos/scottsievert/swix/issues/21","repository_url":"https://api.github.com/repos/scottsievert/swix","labels_url":"https://api.github.com/repos/scottsievert/swix/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/scottsievert/swix/issues/21/comments","events_url":"https://api.github.com/repos/scottsievert/swix/issues/21/events","html_url":"https://github.com/scottsievert/swix/pull/21","id":135049261,"number":21,"title":"Add alternative read csv function","user":{"login":"arondes","id":17297973,"avatar_url":"https://avatars.githubusercontent.com/u/17297973?v=3","gravatar_id":"","url":"https://api.github.com/users/arondes","html_url":"https://github.com/arondes","followers_url":"https://api.github.com/users/arondes/followers","following_url":"https://api.github.com/users/arondes/following{/other_user}","gists_url":"https://api.github.com/users/arondes/gists{/gist_id}","starred_url":"https://api.github.com/users/arondes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arondes/subscriptions","organizations_url":"https://api.github.com/users/arondes/orgs","repos_url":"https://api.github.com/users/arondes/repos","events_url":"https://api.github.com/users/arondes/events{/privacy}","received_events_url":"https://api.github.com/users/arondes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-02-20T08:24:01Z","updated_at":"2016-02-21T02:05:38Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/scottsievert/swix/pulls/21","html_url":"https://github.com/scottsievert/swix/pull/21","diff_url":"https://github.com/scottsievert/swix/pull/21.diff","patch_url":"https://github.com/scottsievert/swix/pull/21.patch"},"body":"The function name is read_csv2. It takes two arguments: filename and whether it contains header (i.e. first row does not contain data, but variable names). I made several changes:\r\n\r\n1. As mentioned above, many times the csv files use first row as variable names, so by setting header=true we will ignore first row. The \"header\" just follows R's routine.\r\n\r\n2. Many times the csv files are created under Windows platform, so the line break is actually \"\\r\\n\" instead of \"\\n\". I check if there is \"\\r\" and delete all of them.\r\n\r\n3. The data in the csv file may not only be numeric. It might be categorical, e.g. \"M\" and \"F\", \"Y\" and \"N\". The original read_csv will ignore these categorical variables. I use different approach: I create a dictionary [String:Int], the key is the categorical value (e.g. \"M\") while the value is Int (e.g. 0). All the keys are stored in a set. A set means identical values will be considered as one element. Once we encounter a categorical value, first we check if it is in the set. If yes, we look up the dictionary and add its value to the data; Otherwise we create a key-value pair and insert the key into the set. So if the column is M,F,F,M, it will be 0,1,1,0 in the final data."},"comment":{"url":"https://api.github.com/repos/scottsievert/swix/issues/comments/186720450","html_url":"https://github.com/scottsievert/swix/pull/21#issuecomment-186720450","issue_url":"https://api.github.com/repos/scottsievert/swix/issues/21","id":186720450,"user":{"login":"scottsievert","id":1320475,"avatar_url":"https://avatars.githubusercontent.com/u/1320475?v=3","gravatar_id":"","url":"https://api.github.com/users/scottsievert","html_url":"https://github.com/scottsievert","followers_url":"https://api.github.com/users/scottsievert/followers","following_url":"https://api.github.com/users/scottsievert/following{/other_user}","gists_url":"https://api.github.com/users/scottsievert/gists{/gist_id}","starred_url":"https://api.github.com/users/scottsievert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottsievert/subscriptions","organizations_url":"https://api.github.com/users/scottsievert/orgs","repos_url":"https://api.github.com/users/scottsievert/repos","events_url":"https://api.github.com/users/scottsievert/events{/privacy}","received_events_url":"https://api.github.com/users/scottsievert/received_events","type":"User","site_admin":false},"created_at":"2016-02-21T02:05:38Z","updated_at":"2016-02-21T02:05:38Z","body":"This seems like a useful pull request -- I'd like to see optional arguments added."}}