osfr
osfr copied to clipboard
osf_upload conflicts = "overwrite" doesn't seem to overwrite?
Hi all, thanks for the osfr package!
I'm struggling a bit with the osf_upload
function. In particular, the overwrite settings aren't working for me. Here's the relevant code. Here's a MWE (minus the specific project, but hopefully that's OK). A side note, the function documentation gives overwrite = TRUE
in the example and that doesn't exist.
> system("touch foo")
> project %>% osf_upload("foo")
# A tibble: 1 x 3
name id meta
<chr> <chr> <list>
1 foo 5f455498746a81028a1a33b1 <named list [3]>
> project %>% osf_upload("foo")
Error: Cannot complete action: file or folder "foo" already exists in this location
HTTP status code 409.
> project %>% osf_upload("foo", conflicts = "overwrite")
Error: Cannot complete action: file or folder "foo" already exists in this location
HTTP status code 409.
> project %>% osf_upload("foo", overwrite = TRUE)
Error in osf_upload(., "foo", overwrite = TRUE) :
unused argument (overwrite = TRUE)
Apologies if I'm missing something here!
You're right that osf_upload()
's docs include an outdated reference to the now deprecated overwrite = TRUE
argument. I'll get that fixed! Thanks for reporting.
As to the error, could you check what version you're using? The following works for me with the current release (v0.2.8):
library(osfr)
#> Automatically registered OSF personal access token
project <- osf_create_project("test")
system("touch foo")
project %>% osf_upload("foo")
#> # A tibble: 1 x 3
#> name id meta
#> <chr> <chr> <list>
#> 1 foo 5f45b2fbd4c603002e1fd3b8 <named list [3]>
project %>% osf_upload("foo")
#> Error: Can't upload file 'foo'.
#> * A file with the same name already exists at the destination.
#> * Use the `conflicts` argument to avoid this error in the future.
project %>% osf_upload("foo", conflicts = "overwrite")
#> # A tibble: 1 x 3
#> name id meta
#> <chr> <chr> <list>
#> 1 foo 5f45b2fbd4c603002e1fd3b8 <named list [3]>
Created on 2020-08-25 by the reprex package (v0.3.0)
I'm up to date with 0.2.8. You're absolutely right though, that reprex works for me.
And it works in the root of my project. But it doesn't work in a subdirectory, the use case I was trying but didn't document in my original example. Try this reprex:
library(osfr)
project <- osf_create_project("test")
project %>% osf_mkdir("test_subdir")
project_subdir <- project %>%
osf_ls_files() %>%
filter(name == "test_subdir")
system("touch foo")
project_subdir %>% osf_upload("foo")
project_subdir %>% osf_upload("foo")
project_subdir %>% osf_upload("foo", conflicts = "overwrite")
Thanks, that helps! Looks like you're the latest victim of this bug which is now fixed in the master branch. If you install the latest dev version
remotes::install_github("ropensci/osfr")
you should be good to go—but please let me know if it doesn't work.
Thank you so much Aaron for the quick responses. I'm sorry I didn't catch those earlier reports.
On Thu, Aug 27, 2020 at 9:47 AM Aaron Wolen [email protected] wrote:
Thanks, that helps! Looks like you're the latest victim of this bug https://github.com/ropensci/osfr/issues/121 which is now fixed https://github.com/ropensci/osfr/pull/129 in the master branch. If you install the latest dev version
remotes::install_github("ropensci/osfr")
you should be good to go—but please let me know if it doesn't work.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ropensci/osfr/issues/130#issuecomment-682065859, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI25F6MF6TJT66CXSTMMXTSC2E3ZANCNFSM4QK6HNLA .
I'm not sure if I should open a new issue or not, but while the previous fix works find for regular sub directories, I have this problem on "sub sub" directories.
Here is a reprex based on the last one, you can see that there are no problems with the sub directory, but the sub sub fails.
library(osfr)
#> Automatically registered OSF personal access token
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
# SETUP
project <- osf_create_project("test")
project %>%
osf_mkdir("test_subdir") %>%
osf_mkdir("test_sub_subdir")
#> # A tibble: 1 x 3
#> name id meta
#> <chr> <chr> <list>
#> 1 test_sub_subdir 5fb6bd5f5502ac032c8c9199 <named list [3]>
project_subdir <- project %>%
osf_ls_files() %>%
filter(name == "test_subdir")
project_sub_subdir <- project %>%
osf_ls_files() %>%
filter(name == "test_subdir") %>%
osf_ls_files() %>%
filter(name == "test_sub_subdir")
system("touch foo")
# TESTING SUB DIRECTORY (No problems)
project_subdir %>% osf_upload("foo")
#> # A tibble: 1 x 3
#> name id meta
#> <chr> <chr> <list>
#> 1 foo 5fb6bd64def8eb0338e7b3c1 <named list [3]>
project_subdir %>% osf_upload("foo")
#> Error: Can't upload file 'foo'.
#> * A file with the same name already exists at the destination.
#> * Use the `conflicts` argument to avoid this error in the future.
project_subdir %>% osf_upload("foo", conflicts = "overwrite")
#> # A tibble: 1 x 3
#> name id meta
#> <chr> <chr> <list>
#> 1 foo 5fb6bd64def8eb0338e7b3c1 <named list [3]>
# TESTING SUB SUB DIRECTORY (409 error)
project_sub_subdir %>% osf_upload("foo")
#> # A tibble: 1 x 3
#> name id meta
#> <chr> <chr> <list>
#> 1 foo 5fb6bd6edef8eb0338e7b3df <named list [3]>
project_sub_subdir %>% osf_upload("foo")
#> Error: Cannot complete action: file or folder "foo" already exists in this location
#> HTTP status code 409.
project_sub_subdir %>% osf_upload("foo", conflicts = "overwrite")
#> Error: Cannot complete action: file or folder "foo" already exists in this location
#> HTTP status code 409.
Created on 2020-11-19 by the reprex package (v0.3.0)
I am now facing a different version of this issue: In the sub-subdirectory case, I do not get an error - instead, no conflicting files are found and the 'new' file is uploaded successfully - but then, the new version does not show up anywhere. Is there any workaround?