r {rethinker} | R Documentation |
ReQL root
Description
Creates ReQL root for building a query.
Usage
r(db, table)
Arguments
db |
DB name; this is optional, and is just a syntax sugar for |
table |
Table name; this is optional, requires db to be given, and is just a syntax sugar for |
Value
ReQL root; use $
(or [[]]
) to chain query terms (like r()$db("test")$table("test")
).
In general, anonymous attributes are passed as attributes while named as term options.
In context of term arguments, named lists are treated as JSON objects (following rjson
package heuristics), unnamed lists and simple vectors as JSON arrays; classes and attributes are ignored.
Term options should be called in the snake case form (for instance return_changes
not returnChanges
), as documented for the original Python driver.
To finalise, use $run
or $runAsync
.
For a comprehensive description of all terms, see RethinkDB API reference; here we give an overview of some:
run(connection , ...) |
Evaluate the query; the function will block until first response from RethinkDB to this query will be received.
May return cursor, an object representing a stream of data on which |
runAsync(connection , callback , ...) |
Evaluate the query; for each datum received |
bracket(...) |
Implementation of the JavaScript |
funcall(function , atts) |
Implementation of the JavaScript |
Note
ReQL is implemented as an environment, thus is mutable unlike most R objects.
To this end, you can use variables for chaining like this r()->query;
query$db("a");
query$table("b")
; but consequently you can't use variables to make a re-usable stub, i.e., this is invalid: r()->query;
query$db("a")$table("aa")$run(...)
query$db("b")$table("bb")$run(...);
.
If you get "trying to apply non-function" error, you likely have misspelled term name or trying to use a non-existent one.
To view raw AST (at any depth), use $query
.
Author(s)
Miron B. Kursa
Examples
## Not run:
#Connect to the RethinkDB instance
cn<-openConnection()
#Get document count in some_db's some_table
r()$db("some_db")$table("some_table")$count()$run(cn)
#...same can be done shorter
r("some_db","some_table")$count()$run(cn)
#Fetch 5 random docs from some_db's some_table...
r("some_db","some_table")$sample(5)$run(cn)->cursor
#...and present as a list`
cursorToList(cursor)
#Insert an element
r("some_db","some_table")$insert(list(id="new",a=1:10,b=list(c=1,d=2)))$run(cn)
#Close connection
close(cn)
## End(Not run)