{"action":"closed","issue":{"url":"https://api.github.com/repos/pbiecek/archivist/issues/125","labels_url":"https://api.github.com/repos/pbiecek/archivist/issues/125/labels{/name}","comments_url":"https://api.github.com/repos/pbiecek/archivist/issues/125/comments","events_url":"https://api.github.com/repos/pbiecek/archivist/issues/125/events","html_url":"https://github.com/pbiecek/archivist/issues/125","id":116155875,"number":125,"title":"archivist's deleteRepo brakes R when unlinking tempdir()","user":{"login":"MarcinKosinski","id":6773454,"avatar_url":"https://avatars.githubusercontent.com/u/6773454?v=3","gravatar_id":"","url":"https://api.github.com/users/MarcinKosinski","html_url":"https://github.com/MarcinKosinski","followers_url":"https://api.github.com/users/MarcinKosinski/followers","following_url":"https://api.github.com/users/MarcinKosinski/following{/other_user}","gists_url":"https://api.github.com/users/MarcinKosinski/gists{/gist_id}","starred_url":"https://api.github.com/users/MarcinKosinski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarcinKosinski/subscriptions","organizations_url":"https://api.github.com/users/MarcinKosinski/orgs","repos_url":"https://api.github.com/users/MarcinKosinski/repos","events_url":"https://api.github.com/users/MarcinKosinski/events{/privacy}","received_events_url":"https://api.github.com/users/MarcinKosinski/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pbiecek/archivist/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/pbiecek/archivist/labels/epic","name":"epic","color":"CFB53B"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-10T17:19:30Z","updated_at":"2015-11-10T21:06:30Z","closed_at":"2015-11-10T21:06:30Z","body":"Today @wchodor  has found a great mistake in our examples. Most of our examples were working on `tempdir()` localizations, but when after some examples we tried to use `deleteRepo` (after a change that unlinked the root directory) we de  facto unlinked the `tempdir()`.\r\n\r\n> `tempdir()` is R's session-wide temporary working directory, so by unlinking it you've removed the location that R uses for all kinds of temporary files.\r\n\r\nSo in other words we brake whole R, which lead to non working functions that were working on temporary directories - great example is `loadFromGithubRepo` that uses `writeBin` and `getBinaryURL`. The brake could be seen even if a person tried to use `?` or `help` / manual page - see attached screenshoot\r\n\r\n![error_1](https://cloud.githubusercontent.com/assets/6773454/11069474/980682ee-87d6-11e5-869b-e8e348354f4b.png)\r\n\r\n\r\nSo in my opinion we shouldn't use `tempdir()` in examples but instead we should use `tempfile()` - as I googled out a similar problem and found that great [stackexchange topic](http://stackoverflow.com/questions/22325820/unlink-function-causing-an-error-for-consequent-and-plot-functions). Below one can see how the proper examples should look like and how they shouldn't now.\r\n\r\nI think before the change in `deleteRepo`, that made finally that root directory is unlinked, all examples worked, but know they need a little modification :) So that's why I proposed a  #124\r\n\r\n# How examples should be created - `tempfile`\r\n\r\n````{R}\r\n> library(archivist)\r\nWelcome to archivist (version: 1.8.8.4).\r\n> \r\n> ls()\r\ncharacter(0)\r\n> exampleRepoDir <- tempfile()\r\n> createEmptyRepo( repoDir = exampleRepoDir )\r\nDirectory /tmp/Rtmpbg9PUh/file13471311e630 did not exist. Forced to create a new directory.\r\n> showLocalRepo(exampleRepoDir)\r\n[1] md5hash     name        createdDate\r\n<0 rows> (or 0-length row.names)\r\n> deleteRepo( exampleRepoDir, TRUE)\r\n> \r\n> setGithubRepo( user=\"MarcinKosinski\", repo=\"Museum\", branch=\"master\",\r\n+ \t\t\t\t\t\t\t repoDirGit=\"ex1\" )\r\n[1] \"ex1\"\r\n> \r\n> loadFromGithubRepo( \"ff575c261c949d073b2895b05d1097c3\", value = T) -> iris22\r\n> ls()\r\n[1] \"exampleRepoDir\" \"iris22\"        \r\n> \r\n````\r\n\r\n# How examples should not be created - `tempdir`\r\n\r\n````{R}\r\n> \r\n> \r\n> ls()\r\n[1] \"exampleRepoDir\" \"iris22\"        \r\n> exampleRepoDir <- tempdir()\r\n> createEmptyRepo( repoDir = exampleRepoDir )\r\n> showLocalRepo(exampleRepoDir)\r\n[1] md5hash     name        createdDate\r\n<0 rows> (or 0-length row.names)\r\n> deleteRepo( exampleRepoDir, TRUE) # here we use unlink function which brokes\r\n> # temporary R directories when unlinks the temporary directory in which\r\n> # R works :)\r\n> \r\n> # so now loadFromGithubRepo can not work because it uses writeBin function which \r\n> # works on temporary R directory \r\n> \r\n> \r\n> loadFromGithubRepo( \"ff575c261c949d073b2895b05d1097c3\", value = T) -> iris22\r\n Show Traceback\r\n \r\n Rerun with Debug\r\n Error in file(con, \"wb\") : cannot open the connection In addition: Warning message:\r\nIn file(con, \"wb\") :\r\n  cannot open file '/tmp/Rtmpbg9PUh/file13477469893f': No such file or directory\r\n> \r\n> # even help pages does not work because we unlinke temporary R directory :)\r\n> ?summary\r\nWarning message:\r\nIn file(out, \"wt\") :\r\n  cannot open file '/tmp/Rtmpbg9PUh/Rhttpd13474a46e8d8': No such file or directory\r\n````\r\n"}}