GithubHelp home page GithubHelp logo

mapic / cosmosr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aaron2012r2/cosmosr

0.0 1.0 0.0 65 KB

Basic functions for interacting with a CosmosDB REST API using the DocumentDB protocols in R

License: MIT License

R 100.00%
r shiny cosmosdb azure rest-api

cosmosr's Introduction

cosmosR

Basic functions in R for simple interactions with a CosmosDB REST API using Document-based storage.

Installation

library('devtools')
install_github('mapic/cosmosR')

Usage

Get all documents from CosmosDB

# import library
library(cosmosR)

# authenticate with CosmosDB container
cosmosAuth("accessKey", "uri", "databaseName", "collectionName")

# get all documents (default: SELECT * FROM c)
data <- cosmosQuery(content.response = TRUE)

# json prettify results
result <- jsonlite::prettify(jsonlite::toJSON(data, auto_unbox = TRUE), 4) 

Query documents from CosmosDB

# import library
library(cosmosR)

# authenticate with CosmosDB container
cosmosAuth("accessKey", "uri", "databaseName", "collectionName")

# example query
sql.full <- "SELECT * FROM c"

# example query: note that with more complicated queries, SELECT * is not allowed, so use SELECT c
sql.full <- 'SELECT c FROM c JOIN samples IN c.samples JOIN tests IN samples.tests WHERE tests.parameter.code = "10112"'

# query with filter, limit results
data <- cosmosQuery(sql.full = sql.full, max.items = 100, content.response = TRUE)

# json prettify results
result <- jsonlite::prettify(jsonlite::toJSON(data, auto_unbox = TRUE), 4)   

Create Document in CosmosDB

You can also create a document, by using the cosmosCreate() function. (Note that the partition key value is required by CosmosDB both as value in argument and as key=value in the document.)

# import library
library(cosmosR)

# authenticate with "lab-orders" container
cosmosAuth("KeyGoesHere", "uri", "dbName", "collName")

# list of keys t
sql_doc <- list(
    id = "unique-id",       # required
    code = "code-1",        # required, must also be added to cosmosCreate() below
    other = "my-value",     # add whatever you want
    more = "more-values"    # add whatever you want
)

# create item in CosmosDB
data <- cosmosCreate(sql.doc = sql_doc, sql.partitionkey_value = "code-1", content.response = TRUE)

# json prettify results
result <- jsonlite::prettify(jsonlite::toJSON(data, auto_unbox = TRUE), 4) 

License

MIT License

Supported by NGI.no.

Based on work by aaron2012r2.

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.