Giter VIP home page Giter VIP logo

Comments (14)

sckott avatar sckott commented on July 24, 2024

Thanks @patperu

But I think there's a difference here between the two things, that is:

toJSON(df[1, ], pretty = TRUE) is taking a row of a data.frame, whereas as.list(df[i,]) is converting to

$author
[1] "Homer"

$poems
$poems[[1]]
[1] "Iliad"   "Odyssey"

note that $poems is a list so that

toJSON(as.list(df[1,])$poems)
#> [["Iliad","Odyssey"]] 

which i think is that double bracketed array you're seeing

So you can just pass in JSON if you want for now

I plan on making it easy to simply pass in a data.frame and then internally we'd either make each row a document, each column, or the whole thing as one document, see #27

from sofa.

patperu avatar patperu commented on July 24, 2024

Thanks @sckott
Now I see the difference. I need to understand this JSON / list thing better.
For now I use 'sapply' to remove the brackets. My working example
https://github.com/patperu/fp7-funding-network-analysis/blob/7cd3cf5b38/R/write2CouchDB.R
Thanks again!

from sofa.

sckott avatar sckott commented on July 24, 2024

@patperu Reinstall the latest from github, and try directly from a data.frame to create documents, see examples https://github.com/sckott/sofa/blob/master/R/doc_create.r#L58-L66

Sorry, but I rearranged parameters in that fxn a bit so that the first is the things passed into the fxn to create documents, so the function can easily behave differently for a json character string, an R list, or a data.frame

See also the new bulk function bulk_create(), examples: https://github.com/sckott/sofa/blob/master/R/bulk_create.R#L16-L21

Or would you rather not create a separate document for each row or column? Is there a different use case you have?

from sofa.

patperu avatar patperu commented on July 24, 2024

Wow, that's great!!
So, with
library('sofa') e9808c4
"rows" and "columns" work perfect!

   doc_create(x, dbname = 'fp7_rows', how = "rows")
   doc_create(x, dbname = 'fp7_cols', how = "columns") 

but with "bulk_create" I get an error

    # bulk
    db_create(dbname = 'fp7_bulk')
    bulk_create(x, dbname="fp7_bulk")
    # Error: (500) - function_clause 

Gist: https://gist.github.com/patperu/4f92213f39877b900b90

And my use case is actually only the "row" variante.

from sofa.

sckott avatar sckott commented on July 24, 2024

bummer. what does that data.frame look like, can you paste in what is in str(x)

from sofa.

patperu avatar patperu commented on July 24, 2024

Yup

str(x)
'data.frame':   1 obs. of  20 variables:
 $ rcn                 : num 108737
 $ reference           : num 609698
 $ acronym             : chr "RENATECH"
 $ programmePga        : chr "FP7-PEOPLE"
 $ programmeCode       : chr "FP7-PEOPLE"
 $ subprogramme        : chr "FP7-PEOPLE-2013-NIGHT"
 $ title               : chr "REsearchers for NAture preservation and TECHnology use for the benefit of the society"
 $ startDate           : chr "2013-05-01 00:00:00"
 $ endDate             : chr "2013-10-31 00:00:00"
 $ projectUrl          : chr NA
 $ totalCost           : num 50616
 $ ecMaxContribution   : num 49997
 $ call                : chr "FP7-PEOPLE-2013-NIGHT"
 $ fundingScheme       : chr "CSA-SA"
 $ coordinator         : chr "INSTITUT JOZEF STEFAN"
 $ organisationId      : num 9113619
 $ coordinatorCountry  : chr "SI"
 $ participants        :List of 1
  ..$ : chr  "FAKULTETA ZA INFORMACIJSKE 'TUDIJE V NOVEM MESTU" "NACIONALNI INSTITUT ZA BIOLOGIJO"
 $ participantCountries:List of 1
  ..$ : chr "SI"
 $ subjects            :List of 1
  ..$ : chr "LIF"

from sofa.

patperu avatar patperu commented on July 24, 2024

@sckott ,
I get the error also when running the 'bulk_create' example with 'mtcars'.
'iris' is fine.

from sofa.

sckott avatar sckott commented on July 24, 2024

@patperu i think it may be lists within the data.frame (e.g., column participants) that's causing the problem

p.s. i just pushed up changes to add list and character methods for bulk_create() see examples

from sofa.

sckott avatar sckott commented on July 24, 2024

@patperu can paste in the output of dput(x) here? I tried to recreate that data.frame locally, and I think I did so, and it worked for me, so I'm not sure if I have a diff. data.frame than you or do you have the latest changes form this repo?

from sofa.

patperu avatar patperu commented on July 24, 2024

Hi @sckott No, it's still not working. Here is the df structure:

structure(list(rcn = 108737, reference = 609698, acronym = "RENATECH", 
    programmePga = "FP7-PEOPLE", programmeCode = "FP7-PEOPLE", 
    subprogramme = "FP7-PEOPLE-2013-NIGHT", title = "REsearchers for NAture preservation and TECHnology use for the benefit of the society", 
    startDate = "2013-05-01 00:00:00", endDate = "2013-10-31 00:00:00", 
    projectUrl = NA_character_, totalCost = 50616, ecMaxContribution = 49997, 
    call = "FP7-PEOPLE-2013-NIGHT", fundingScheme = "CSA-SA", 
    coordinator = "INSTITUT JOZEF STEFAN", organisationId = 9113619, 
    coordinatorCountry = "SI", participants = list(c("FAKULTETA ZA INFORMACIJSKE 'TUDIJE V NOVEM MESTU", 
    "NACIONALNI INSTITUT ZA BIOLOGIJO")), participantCountries = list(
        "SI"), subjects = list("LIF")), .Names = c("rcn", "reference", 
"acronym", "programmePga", "programmeCode", "subprogramme", "title", 
"startDate", "endDate", "projectUrl", "totalCost", "ecMaxContribution", 
"call", "fundingScheme", "coordinator", "organisationId", "coordinatorCountry", 
"participants", "participantCountries", "subjects"), row.names = 5L, class = "data.frame")

And I still get an error with

bulk_create(mtcars, dbname="bulktest_f") 

I think I'm using the latest version

 package * version  date       source                      
 sofa      0.1.7.99 2015-03-12 Github (sckott/sofa@aaaf2fc)

from sofa.

sckott avatar sckott commented on July 24, 2024

Thanks! Can you paste in your devtools::session_info() or sessionInfo() - Errors may be coming from different versions of dependencies, likely jsonlite could be the problem

from sofa.

patperu avatar patperu commented on July 24, 2024

Yes sure!

> devtools::session_info()$packages
 package    * version  date       source                      
 bitops     * 1.0-6    2013-08-17 CRAN (R 3.1.2)              
 devtools   * 1.7.0    2015-01-17 CRAN (R 3.1.2)              
 httr       * 0.6.1    2015-01-01 CRAN (R 3.1.2)              
 jsonlite   * 0.9.14   2014-12-01 CRAN (R 3.1.2)              
 plyr       * 1.8.1    2014-02-26 CRAN (R 3.1.2)              
 Rcpp       * 0.11.5   2015-03-06 CRAN (R 3.1.2)              
 RCurl      * 1.95-4.5 2014-12-06 CRAN (R 3.1.2)              
 rstudioapi * 0.2      2014-12-31 CRAN (R 3.1.2)              
 sofa         0.1.7.99 2015-03-12 Github (sckott/sofa@aaaf2fc)
 stringr    * 0.6.2    2012-12-06 CRAN (R 3.1.2)   

from sofa.

patperu avatar patperu commented on July 24, 2024

Hello @sckott
here comes the rest

> devtools::session_info()
Session info --------------
 setting  value                                      
 version  R version 3.1.2 Patched (2015-01-10 r67415)
 system   x86_64, mingw32                            
 ui       Rgui                                       
 language (EN)                                       
 collate  German_Germany.1252                        
 tz       Europe/Berlin                              

from sofa.

sckott avatar sckott commented on July 24, 2024

@patperu Okay, install again and tell me what you get

from sofa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.