Debian Codegraph @

man/curl.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/curl.R
3 \name{curl}
4 \alias{curl}
5 \title{Curl connection interface}
6 \usage{
7 curl(url = "https://hb.cran.dev/get", open = "", handle = new_handle())
8 }
9 \arguments{
10 \item{url}{character string. See examples.}
11
12 \item{open}{character string. How to open the connection if it should be opened
13 initially. Currently only "r" and "rb" are supported.}
14
15 \item{handle}{a curl handle object}
16 }
17 \description{
18 Drop-in replacement for base \code{\link[=url]{url()}} that supports https, ftps,
19 gzip, deflate, etc. Default behavior is identical to \code{\link[=url]{url()}}, but
20 request can be fully configured by passing a custom \code{\link[=handle]{handle()}}.
21 }
22 \details{
23 As of version 2.3 curl connections support \code{open(con, blocking = FALSE)}.
24 In this case \code{readBin} and \code{readLines} will return immediately with data
25 that is available without waiting. For such non-blocking connections the caller
26 needs to call \code{\link[=isIncomplete]{isIncomplete()}} to check if the download has completed
27 yet.
28 }
29 \examples{
30 \dontrun{
31 con <- curl("https://hb.cran.dev/get")
32 readLines(con)
33
34 # Auto-opened connections can be recycled
35 open(con, "rb")
36 bin <- readBin(con, raw(), 999)
37 close(con)
38 rawToChar(bin)
39
40 # HTTP error
41 curl("https://hb.cran.dev/status/418", "r")
42
43 # Follow redirects
44 readLines(curl("https://hb.cran.dev/redirect/3"))
45
46 # Error after redirect
47 curl("https://hb.cran.dev/redirect-to?url=https://hb.cran.dev/status/418", "r")
48
49 # Auto decompress Accept-Encoding: gzip / deflate (rfc2616 #14.3)
50 readLines(curl("https://hb.cran.dev/gzip"))
51 readLines(curl("https://hb.cran.dev/deflate"))
52
53 # Binary support
54 buf <- readBin(curl("https://hb.cran.dev/bytes/98765", "rb"), raw(), 1e5)
55 length(buf)
56
57 # Read file from disk
58 test <- paste0("file://", system.file("DESCRIPTION"))
59 readLines(curl(test))
60
61 # Other protocols
62 read.csv(curl("ftp://cran.r-project.org/pub/R/CRAN_mirrors.csv"))
63 readLines(curl("ftps://test.rebex.net:990/readme.txt"))
64 readLines(curl("gopher://quux.org/1"))
65
66 # Streaming data
67 con <- curl("http://jeroen.github.io/data/diamonds.json", "r")
68 while(length(x <- readLines(con, n = 5))){
69 print(x)
70 }
71
72 # Stream large dataset over https with gzip
73 library(jsonlite)
74 con <- gzcon(curl("https://jeroen.github.io/data/nycflights13.json.gz"))
75 nycflights <- stream_in(con)
76 }
77
78 }