{"action":"closed","number":21,"pull_request":{"url":"https://api.github.com/repos/scottsievert/swix/pulls/21","id":60042096,"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","issue_url":"https://api.github.com/repos/scottsievert/swix/issues/21","number":21,"state":"closed","locked":false,"title":"Enhance 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},"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.","created_at":"2016-02-20T08:24:01Z","updated_at":"2016-02-23T02:09:33Z","closed_at":"2016-02-23T02:09:33Z","merged_at":"2016-02-23T02:09:33Z","merge_commit_sha":"101e18694c993008e99525037130f0ce4b070526","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scottsievert/swix/pulls/21/commits","review_comments_url":"https://api.github.com/repos/scottsievert/swix/pulls/21/comments","review_comment_url":"https://api.github.com/repos/scottsievert/swix/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scottsievert/swix/issues/21/comments","statuses_url":"https://api.github.com/repos/scottsievert/swix/statuses/cc1f59d46556ae9cc94e3fb0298a5bf7d0c58de8","head":{"label":"arondes:patch-1","ref":"patch-1","sha":"cc1f59d46556ae9cc94e3fb0298a5bf7d0c58de8","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},"repo":{"id":52143524,"name":"swix","full_name":"arondes/swix","owner":{"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},"private":false,"html_url":"https://github.com/arondes/swix","description":"Swift Matrix  Library","fork":true,"url":"https://api.github.com/repos/arondes/swix","forks_url":"https://api.github.com/repos/arondes/swix/forks","keys_url":"https://api.github.com/repos/arondes/swix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/arondes/swix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/arondes/swix/teams","hooks_url":"https://api.github.com/repos/arondes/swix/hooks","issue_events_url":"https://api.github.com/repos/arondes/swix/issues/events{/number}","events_url":"https://api.github.com/repos/arondes/swix/events","assignees_url":"https://api.github.com/repos/arondes/swix/assignees{/user}","branches_url":"https://api.github.com/repos/arondes/swix/branches{/branch}","tags_url":"https://api.github.com/repos/arondes/swix/tags","blobs_url":"https://api.github.com/repos/arondes/swix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/arondes/swix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/arondes/swix/git/refs{/sha}","trees_url":"https://api.github.com/repos/arondes/swix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/arondes/swix/statuses/{sha}","languages_url":"https://api.github.com/repos/arondes/swix/languages","stargazers_url":"https://api.github.com/repos/arondes/swix/stargazers","contributors_url":"https://api.github.com/repos/arondes/swix/contributors","subscribers_url":"https://api.github.com/repos/arondes/swix/subscribers","subscription_url":"https://api.github.com/repos/arondes/swix/subscription","commits_url":"https://api.github.com/repos/arondes/swix/commits{/sha}","git_commits_url":"https://api.github.com/repos/arondes/swix/git/commits{/sha}","comments_url":"https://api.github.com/repos/arondes/swix/comments{/number}","issue_comment_url":"https://api.github.com/repos/arondes/swix/issues/comments{/number}","contents_url":"https://api.github.com/repos/arondes/swix/contents/{+path}","compare_url":"https://api.github.com/repos/arondes/swix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/arondes/swix/merges","archive_url":"https://api.github.com/repos/arondes/swix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/arondes/swix/downloads","issues_url":"https://api.github.com/repos/arondes/swix/issues{/number}","pulls_url":"https://api.github.com/repos/arondes/swix/pulls{/number}","milestones_url":"https://api.github.com/repos/arondes/swix/milestones{/number}","notifications_url":"https://api.github.com/repos/arondes/swix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/arondes/swix/labels{/name}","releases_url":"https://api.github.com/repos/arondes/swix/releases{/id}","deployments_url":"https://api.github.com/repos/arondes/swix/deployments","created_at":"2016-02-20T08:10:45Z","updated_at":"2016-02-20T08:10:48Z","pushed_at":"2016-02-22T01:03:54Z","git_url":"git://github.com/arondes/swix.git","ssh_url":"git@github.com:arondes/swix.git","clone_url":"https://github.com/arondes/swix.git","svn_url":"https://github.com/arondes/swix","homepage":"http://scottsievert.com/swix/","size":40432,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scottsievert:master","ref":"master","sha":"0a8cd32e629ddf6462a91c2d88f8948fc954808e","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},"repo":{"id":20730415,"name":"swix","full_name":"scottsievert/swix","owner":{"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},"private":false,"html_url":"https://github.com/scottsievert/swix","description":"Swift Matrix  Library","fork":false,"url":"https://api.github.com/repos/scottsievert/swix","forks_url":"https://api.github.com/repos/scottsievert/swix/forks","keys_url":"https://api.github.com/repos/scottsievert/swix/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scottsievert/swix/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scottsievert/swix/teams","hooks_url":"https://api.github.com/repos/scottsievert/swix/hooks","issue_events_url":"https://api.github.com/repos/scottsievert/swix/issues/events{/number}","events_url":"https://api.github.com/repos/scottsievert/swix/events","assignees_url":"https://api.github.com/repos/scottsievert/swix/assignees{/user}","branches_url":"https://api.github.com/repos/scottsievert/swix/branches{/branch}","tags_url":"https://api.github.com/repos/scottsievert/swix/tags","blobs_url":"https://api.github.com/repos/scottsievert/swix/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scottsievert/swix/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scottsievert/swix/git/refs{/sha}","trees_url":"https://api.github.com/repos/scottsievert/swix/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scottsievert/swix/statuses/{sha}","languages_url":"https://api.github.com/repos/scottsievert/swix/languages","stargazers_url":"https://api.github.com/repos/scottsievert/swix/stargazers","contributors_url":"https://api.github.com/repos/scottsievert/swix/contributors","subscribers_url":"https://api.github.com/repos/scottsievert/swix/subscribers","subscription_url":"https://api.github.com/repos/scottsievert/swix/subscription","commits_url":"https://api.github.com/repos/scottsievert/swix/commits{/sha}","git_commits_url":"https://api.github.com/repos/scottsievert/swix/git/commits{/sha}","comments_url":"https://api.github.com/repos/scottsievert/swix/comments{/number}","issue_comment_url":"https://api.github.com/repos/scottsievert/swix/issues/comments{/number}","contents_url":"https://api.github.com/repos/scottsievert/swix/contents/{+path}","compare_url":"https://api.github.com/repos/scottsievert/swix/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scottsievert/swix/merges","archive_url":"https://api.github.com/repos/scottsievert/swix/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scottsievert/swix/downloads","issues_url":"https://api.github.com/repos/scottsievert/swix/issues{/number}","pulls_url":"https://api.github.com/repos/scottsievert/swix/pulls{/number}","milestones_url":"https://api.github.com/repos/scottsievert/swix/milestones{/number}","notifications_url":"https://api.github.com/repos/scottsievert/swix/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scottsievert/swix/labels{/name}","releases_url":"https://api.github.com/repos/scottsievert/swix/releases{/id}","deployments_url":"https://api.github.com/repos/scottsievert/swix/deployments","created_at":"2014-06-11T15:25:58Z","updated_at":"2016-02-22T17:45:06Z","pushed_at":"2016-02-23T02:09:33Z","git_url":"git://github.com/scottsievert/swix.git","ssh_url":"git@github.com:scottsievert/swix.git","clone_url":"https://github.com/scottsievert/swix.git","svn_url":"https://github.com/scottsievert/swix","homepage":"http://scottsievert.com/swix/","size":40440,"stargazers_count":315,"watchers_count":315,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":48,"mirror_url":null,"open_issues_count":1,"forks":48,"open_issues":1,"watchers":315,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scottsievert/swix/pulls/21"},"html":{"href":"https://github.com/scottsievert/swix/pull/21"},"issue":{"href":"https://api.github.com/repos/scottsievert/swix/issues/21"},"comments":{"href":"https://api.github.com/repos/scottsievert/swix/issues/21/comments"},"review_comments":{"href":"https://api.github.com/repos/scottsievert/swix/pulls/21/comments"},"review_comment":{"href":"https://api.github.com/repos/scottsievert/swix/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scottsievert/swix/pulls/21/commits"},"statuses":{"href":"https://api.github.com/repos/scottsievert/swix/statuses/cc1f59d46556ae9cc94e3fb0298a5bf7d0c58de8"}},"merged":true,"mergeable":null,"mergeable_state":"unknown","merged_by":{"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},"comments":13,"review_comments":0,"commits":7,"additions":109,"deletions":0,"changed_files":1}}