File: libcurl.R

package info (click to toggle)
r-base 4.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 112,924 kB
  • sloc: ansic: 291,338; fortran: 111,889; javascript: 14,798; yacc: 6,154; sh: 5,689; makefile: 5,239; tcl: 4,562; perl: 963; objc: 791; f90: 758; asm: 258; java: 31; sed: 1
file content (42 lines) | stat: -rw-r--r-- 1,300 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
## These are tests that require libcurl functionality (available
## everywhere as from R 4.2.0) and a working Internet connection.

## Nowadays method = "libcurl" is the default everywhere for http[s]://

## This used to check that https:// worked and skip if not, but then
## all the tests redirected to https://

## check basic Internet access
if(.Platform$OS.type == "unix" &&
   is.null(nsl("cran.r-project.org"))) q()

tf <- tempfile()
download.file("https://cran.r-project.org/", tf)
file.size(tf)
unlink(tf)


## test url connections on http -- this now redirects to https://
str(readLines(zz <- url("http://cran.r-project.org/")))
zz
stopifnot(identical(summary(zz)$class, "url-libcurl"))
close(zz)
## and check that direct https:// works
str(readLines(zz <- url("https://cran.r-project.org/")))
close(zz)

##  via read.table (which closes the connection) -- this now redirects to https://
tail(read.table(url("http://www.stats.ox.ac.uk/pub/datasets/csb/ch11b.dat")))

## check option works
options(url.method = "libcurl")
zz <- url("http://www.stats.ox.ac.uk/pub/datasets/csb/ch11b.dat")
stopifnot(identical(summary(zz)$class, "url-libcurl"))
close(zz)

curlGetHeaders("https://developer.r-project.org")
example(curlGetHeaders, run.donttest = TRUE)

showConnections(all = TRUE)

proc.time()