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

when creating a document in cloudant numbers are rounded #66

Closed
mjvanhasselt opened this issue Nov 8, 2018 · 4 comments
Closed

when creating a document in cloudant numbers are rounded #66

mjvanhasselt opened this issue Nov 8, 2018 · 4 comments
Milestone

Comments

@mjvanhasselt
Copy link

mjvanhasselt commented Nov 8, 2018

Session Info
> sessionInfo()
R version 3.5.1 (2018-07-02)
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.3.0

loaded via a namespace (and not attached):
 [1] compiler_3.5.1  R6_2.3.0        tools_3.5.1     httpcode_0.2.0  yaml_2.2.0      curl_3.2       
 [7] Rcpp_0.12.19    urltools_1.7.1  triebeard_0.3.0 crul_0.6.0      jsonlite_1.5   

Hi,

I have a cloudant database. In this database there are documents with "_id" fields that were randomly generated at creation. However, I wanted to change the "_id" fields of the documents to give it a time based value, since I need to query the database based on date/time constraints.

I read somewhere that the only way I could change the "_id" values of the documents, would be by creating new documents with the same content, however specifying the "_id" field while creating these new documents. (And subsequently, I could delete the original documents).

The JSON documents in my database are rather large, but to reproduce my issue, I have a small similar JSON document:

{
"_id": "4b752d5686dce33023f75d20e269070f",
"_rev": "4-e8fca21cb509c77079b1ff23189ed451",
"name": "'s-Graveland",
"geoPoint": {
"latitude": 52.252765,
"longitude": 5.12106
}
}

So, I followed the above described approach; for one document this approach looks like this:

all_docs <- db_alldocs(conn, "test") # find all documents in the database
doc_with_old_id <- doc_get(conn, dbname = "test", docid = "4b752d5686dce33023f75d20e269070f" # get a specific document
doc_with_new_id <- doc_old_id[3:4] # assign the content (without "_id" to a new object
new_id <- "123" # define the new "_id"
doc_create(conn, "test", doc_new_id, docid = new_id) # create a new document with the specific "_id"

Where conn is a cushion object.

As you can see the lattitude in the original JSON object has 6 decimal places and the longitude has 5 decimal places.

When I use doc_create to create the new document with the specific "_id" field and I took a look at the contents of this new file, I found out that the original numbers are rounded:

{
"_id": "123",
"_rev": "1-0624464ffcf2f13d30874a761cca431d",
"name": "'s-Graveland",
"geoPoint": {
"latitude": 52.2528,
"longitude": 5.1211
}
}

So, the lattitude has now 4 decimal places instead of 6 and the longitude has 4 decimal places instead of the original 5.

Concluding, is it possible to change the "_id" field (or as I did, create a new document and put into it the content of an old document), without rounding any numbers?

Thanks in advance!

@sckott
Copy link
Contributor

sckott commented Nov 9, 2018

thanks for the report @mjvanhasselt - i'll have a look

@sckott sckott added this to the v0.4 milestone Nov 9, 2018
sckott added a commit that referenced this issue Nov 9, 2018
added a %||% fxn in zzz.r
change internal fxn check_inputs() to pass getOptions(digits) to digits param in jsonlite::toJSON
add docs to pkg level man file and doc_create about how to set digits
bump minor version
@sckott
Copy link
Contributor

sckott commented Nov 9, 2018

@mjvanhasselt reinstall and try again. You'll need to set the digits option like options(digits = 10) or similar - i added docs about this to ?doc_create and ?sofa-package

let me know what you think

@mjvanhasselt
Copy link
Author

@sckott Thanks for your help: I compared the one installed through CRAN and the one installed from github (by devtools::install_github("ropensci/sofa").

Result: The numbers are not rounded off anymore when using the version obtained from github.

So, thanks very much for this change :)

@sckott
Copy link
Contributor

sckott commented Nov 12, 2018

great, glad it works.

@sckott sckott closed this as completed Nov 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants