library("knitr") hook_output <- knitr::knit_hooks$get("output") knitr::knit_hooks$set(output = function(x, options) { lines <- options$output.lines if (is.null(lines)) { return(hook_output(x, options)) # pass to default hook } x <- unlist(strsplit(x, "\n")) more <- "..." if (length(lines)==1) { # first n lines if (length(x) > lines) { # truncate the output, but add .... x <- c(head(x, lines), more) } } else { x <- c(if (abs(lines[1])>1) more else NULL, x[lines], if (length(x)>lines[abs(length(lines))]) more else NULL ) } # paste these lines together x <- paste(c(x, ""), collapse = "\n") hook_output(x, options) }) knitr::opts_chunk$set( comment = "#>", collapse = TRUE, warning = FALSE, message = FALSE )
An R DSL for Elasticsearch
v1.4 of Elasticsearch.You're fine running ES locally on your machine, but be careful just throwing up ES on a server with a public IP address - make sure to think about security.
install.packages("devtools") devtools::install_github("ropensci/elasticdsl")
library('elasticdsl')
Instructions for installing, upgrading, starting Elasticsearch, and loading example data at ropensci/elastic
The function elastic::connect() is used before doing anything else to set the connection details to your remote or local elasticdslsearch store. The details created by connect() are written to your options for the current session, and are used by elasticdsl functions.
elastic::connect(es_port = 9200)
index("shakespeare")
index("shakespeare") %>% filter() %>% ids(c(1, 2, 150)) %>% explain() # doesn't exist yet
res <- index("shakespeare") %>% filter() %>% ids(c(1, 2)) %>% exec()
index("shakespeare") %>% ids(c(1, 2)) %>% exec() %>% n()
index("shakespeare") %>% filter() %>% prefix(speaker = "we") %>% size(2) %>% fields(play_name) %>% exec() %>% n()
s <- index("shakespeare") %>% filter() %>% prefix(speaker = "we") %>% size(2)
s %>% fields(play_name) %>% exec() %>% .$hits %>% .$hits
s %>% fields(play_name, text_entry) %>% exec() %>% .$hits %>% .$hits
s %>% fields(play_name, text_entry, line_id) %>% exec() %>% .$hits %>% .$hits
Filters are boolean queries and are much more computationally efficient than queries.
prefix filter
index("shakespeare") %>% filter() %>% prefix(speaker = "we") %>% exec() %>% n()
ids filter
index("shakespeare") %>% filter() %>% ids(c(1, 2, 150)) %>% exec() %>% n()
geoshape query (filters have a much larger range of geo queries)
index("geoshape") %>% geoshape(field = "location", type = "envelope", coordinates = list(c(-30, 50), c(30, 0))) %>% n()
elasticdsl in R doing citation(package = 'elasticdsl')Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.