{"id":13401481,"url":"https://github.com/mikelove/r-gotchas","last_synced_at":"2025-09-17T15:31:16.737Z","repository":{"id":17483063,"uuid":"20264442","full_name":"mikelove/r-gotchas","owner":"mikelove","description":"R gotchas","archived":false,"fork":false,"pushed_at":"2015-07-31T15:44:34.000Z","size":214,"stargazers_count":46,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-30T03:42:56.080Z","etag":null,"topics":["gotchas","programming","r"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikelove.png","metadata":{"files":{"readme":"README.R","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-28T16:26:13.000Z","updated_at":"2021-03-20T07:50:32.000Z","dependencies_parsed_at":"2022-09-02T12:11:34.995Z","dependency_job_id":null,"html_url":"https://github.com/mikelove/r-gotchas","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikelove%2Fr-gotchas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikelove%2Fr-gotchas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikelove%2Fr-gotchas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikelove%2Fr-gotchas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikelove","download_url":"https://codeload.github.com/mikelove/r-gotchas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233401680,"owners_count":18670809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gotchas","programming","r"],"created_at":"2024-07-30T19:01:03.250Z","updated_at":"2025-09-17T15:31:11.418Z","avatar_url":"https://github.com/mikelove.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"## ------------------------------------------------------------------------\nm \u003c- matrix(1:6, ncol=3)\nm\nm[1,] # vector\nm[,1] # vector\nm[1,,drop=FALSE] # matrix\n\n## ------------------------------------------------------------------------\ndf \u003c- data.frame(a=1:3,b=4:6)\ndf\ndf[1,] # data.frame\ndf[,1] # vector\ndf[,1,drop=FALSE] # data.frame\n\n## ------------------------------------------------------------------------\ndf \u003c- data.frame(a=c(\"10\",\"11\",\"12\"))\nas.numeric(df$a) + 1\ndf \u003c- data.frame(a=c(\"10\",\"11\",\"12\"), stringsAsFactors=FALSE)\nas.numeric(df$a) + 1\n\n## ------------------------------------------------------------------------\nc(TRUE,TRUE,FALSE) \u0026 c(FALSE,TRUE,TRUE) # element-wise\nc(TRUE,TRUE,FALSE) \u0026\u0026 c(FALSE,TRUE,TRUE) # just the first\nx \u003c- \"hi\"\nis.numeric(x) \u0026\u0026 x + 1 # evaluates left to right\nis.numeric(x) \u0026 x + 1 # produces error\n\n## ------------------------------------------------------------------------\nm \u003c- matrix(1:6, ncol=3)\nm^2\napply(m, 2, `^`, 2) # column-wise, ok\napply(m, 1, `^`, 2) # gives back row-wise operation as columns\n\n## ------------------------------------------------------------------------\ndf \u003c- data.frame(\"test-it-#1\"=1:2)\ndf\nmake.names(\"test-it-#1\") # this function is used\n\n## ------------------------------------------------------------------------\ndf \u003c- data.frame(a=1:2,b=3:4,c=5:6,d=7:8)\ndf[,-(2:3)] # numeric index ok \ndf[,-c(\"b\",\"c\")] # not character index\nsubset(df, select=-c(b,c)) # by name works here\n\n## ------------------------------------------------------------------------\nx \u003c- numeric(0)\n1:length(x)\nseq_len(length(x))\nseq_along(x)\n\n## ------------------------------------------------------------------------\nx \u003c- c(1,2,NA)\nwhich(x == NA)\nwhich(is.na(x))\ny \u003c- NULL\ny == NULL\nis.null(y)\n\n## ------------------------------------------------------------------------\nm \u003c- matrix(1:4,ncol=2)\nwrite.csv(m,file=\"matrix.csv\")\nread.csv(\"matrix.csv\")\nread.csv(\"matrix.csv\",row.names=1)\n\n## ----,echo=FALSE,results=\"hide\"------------------------------------------\nfile.remove(\"matrix.csv\")\n\n## ------------------------------------------------------------------------\nf \u003c- function() {\n  y \u003c- 1:10\n  form \u003c- ~ 1\n  form\n}\nget(\"y\", environment(f()))\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikelove%2Fr-gotchas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikelove%2Fr-gotchas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikelove%2Fr-gotchas/lists"}