Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc_attach_get throws error 'arg' must be NULL or a character vector #58

Closed
gtumuluri opened this issue Oct 16, 2017 · 6 comments
Closed
Labels
Milestone

Comments

@gtumuluri
Copy link

I have a document in Cloudant with an attachment and I am trying to retrieve the attachment content using doc_attach_get call in the sofa package. However, I get an error as follows. When I 'override' the function from the sofa package with a trimmed down version of that same function, it works fine.

Why is match.arg not working even though I am passing the arguments exactly as described in the package documentation? What am I missing?

Error scenario with the built-in sofa package function:

doc_attach_get(myCushion, 'my-db', '1025a2d03ff61105ce5270930143a748', attname = 'file_name')
Error in match.arg(as, c("list", "json")) :
  'arg' must be NULL or a character vector

Overrriding the built-in sofa package function as follows, and trying again:

doc_attach_get <- function (cushion, dbname, docid, attname, type = "raw", ...)
+ {
+   url <- file.path(cushion$make_url(), dbname, docid, attname)
+   res <- GET(url, content_type_json(), cushion$get_headers(),
+              ...)
+   content(res, as = type, encoding = "UTF-8")
+ }
doc_attach_get(myCushion, 'my-db', '1025a2d03ff61105ce5270930143a748', attname = 'file_name')
    [1] 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 02 58 00 00 01 e0
   [25] 08 06 00 00 00 79 17 13 59 00 00 00 04 67 41 4d 41 00 00 b1 8f 0b fc 61
   [49] 05 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 00 20 63 48 52 4d 00 00
   [73] 7a 26 00 00 80 84 00 00 fa 00 00 00 80 e8 00 00 75 30 00 00 ea 60 00 00
   [97] 3a 98 00 00 17 70 9c ba 51 3c 00 00 00 06 62 4b 47 44 00 ff 00 ff 00 ff
  [121] a0 bd a7 93 00 00 00 09 70 48 59 73 00 00 0b 13 00 00 0b 13 01 00 9a 9c
  [145] 18 00 00 61 39 49 44 41 54 7
@sckott
Copy link
Contributor

sckott commented Oct 18, 2017

thanks @gtumuluri Can you include the output of sessionInfo() ?

@gtumuluri
Copy link
Author

On one of the machines, it is the following. I also tried on a Linux instance with the latest development package, which is version ....900 I think. I have that EC2 instance terminated, and can't provide sessionInfo().

R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] sofa_0.2.0        data.table_1.10.4 bindrcpp_0.2      ibmdbR_1.49.0     arules_1.5-2      Matrix_1.2-11    
 [7] RODBC_1.3-15      jsonlite_1.5      stringr_1.2.0     tidyr_0.7.0       dplyr_0.7.2      

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.12     bindr_0.1        magrittr_1.5     MASS_7.3-47      tidyselect_0.1.1 munsell_0.4.3   
 [7] colorspace_1.3-2 lattice_0.20-35  R6_2.2.2         rlang_0.1.2      httr_1.3.1       plyr_1.8.4      
[13] tools_3.4.1      grid_3.4.1       rpart.plot_2.1.2 gtable_0.2.0     lazyeval_0.2.0   assertthat_0.2.0
[19] tibble_1.3.3     ggplot2_2.2.1    purrr_0.2.3      rpart_4.1-11     glue_1.1.1       stringi_1.1.5   
[25] compiler_3.4.1   scales_0.4.1     pkgconfig_2.0.1 

@sckott
Copy link
Contributor

sckott commented Oct 19, 2017

thanks

@sckott
Copy link
Contributor

sckott commented Oct 20, 2017

@gtumuluri try it again after reinstalling like devtools::install_github("ropensci/sofa")

@sckott sckott added this to the v0.3 milestone Oct 20, 2017
@ghost
Copy link

ghost commented Nov 29, 2017

Installed and tested with the dev version and it works! Thank you.

x <- doc_attach_get(myCushion, 'my-db', '1025a2d03ff61105ce5270930143a748', attname = 'file_name')

length(x)
[1] 5572

In the DB:

"_attachments": {
    "file_name": {
      "content_type": "image/png",
      "revpos": 8,
      "digest": "md5-GtSHlXs/7RMVVXdGHVRzEg==",
      "length": 5572,

@sckott
Copy link
Contributor

sckott commented Nov 29, 2017

great, glad it works

@sckott sckott closed this as completed Nov 29, 2017
@sckott sckott added the bug label Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants