Examples for 'crul::writing-options'


Writing data options

Aliases: writing-options

Keywords:

### ** Examples

## Not run: 
##D # write to disk
##D (x <- HttpClient$new(url = "https://hb.opencpu.org"))
##D f <- tempfile()
##D res <- x$get("get", disk = f)
##D res$content # when using write to disk, content is a path
##D readLines(res$content)
##D close(file(f))
##D 
##D # streaming response
##D (x <- HttpClient$new(url = "https://hb.opencpu.org"))
##D res <- x$get('stream/50', stream = function(x) cat(rawToChar(x)))
##D res$content # when streaming, content is NULL
##D 
##D 
##D ## Async
##D (cc <- Async$new(
##D   urls = c(
##D     'https://hb.opencpu.org/get?a=5',
##D     'https://hb.opencpu.org/get?foo=bar',
##D     'https://hb.opencpu.org/get?b=4',
##D     'https://hb.opencpu.org/get?stuff=things',
##D     'https://hb.opencpu.org/get?b=4&g=7&u=9&z=1'
##D   )
##D ))
##D files <- replicate(5, tempfile())
##D (res <- cc$get(disk = files, verbose = TRUE))
##D lapply(files, readLines)
##D 
##D ## Async varied
##D ### disk
##D f <- tempfile()
##D g <- tempfile()
##D req1 <- HttpRequest$new(url = "https://hb.opencpu.org/get")$get(disk = f)
##D req2 <- HttpRequest$new(url = "https://hb.opencpu.org/post")$post(disk = g)
##D req3 <- HttpRequest$new(url = "https://hb.opencpu.org/get")$get()
##D (out <- AsyncVaried$new(req1, req2, req3))
##D out$request()
##D out$content()
##D readLines(f)
##D readLines(g)
##D out$parse()
##D close(file(f))
##D close(file(g))
##D 
##D ### stream - to console
##D fun <- function(x) print(x)
##D req1 <- HttpRequest$new(url = "https://hb.opencpu.org/get"
##D )$get(query = list(foo = "bar"), stream = fun)
##D req2 <- HttpRequest$new(url = "https://hb.opencpu.org/get"
##D )$get(query = list(hello = "world"), stream = fun)
##D (out <- AsyncVaried$new(req1, req2))
##D out$request()
##D out$content()
##D 
##D ### stream - to an R object
##D lst <- list()
##D fun <- function(x) lst <<- append(lst, list(x))
##D req1 <- HttpRequest$new(url = "https://hb.opencpu.org/get"
##D )$get(query = list(foo = "bar"), stream = fun)
##D req2 <- HttpRequest$new(url = "https://hb.opencpu.org/get"
##D )$get(query = list(hello = "world"), stream = fun)
##D (out <- AsyncVaried$new(req1, req2))
##D out$request()
##D lst
##D cat(vapply(lst, function(z) rawToChar(z$content), ""), sep = "\n")
## End(Not run)

[Package crul version 1.5.0 Index]