Rev 47058 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
R version 2.7.0 Under development (unstable) (2008-03-18 r44795)Copyright (C) 2008 The R Foundation for Statistical ComputingISBN 3-900051-07-0R is free software and comes with ABSOLUTELY NO WARRANTY.You are welcome to redistribute it under certain conditions.Type 'license()' or 'licence()' for distribution details.R is a collaborative project with many contributors.Type 'contributors()' for more information and'citation()' on how to cite R or R packages in publications.Type 'demo()' for some demos, 'help()' for on-line help, or'help.start()' for an HTML browser interface to help.Type 'q()' to quit R.> ## These are tests that require socket and internet functionality, and> ## a working Internet connection.> ## We attempt to test for those.>> if(!capabilities()["http/ftp"]) {+ warning("no internet capabilities")+ q()+ }>> if(.Platform$OS.type == "unix" &&+ is.null(nsl("cran.r-project.org"))) q()>> # test do_download.> nrow(available.packages(contrib.url("http://cran.r-project.org")))[1] 1600>> # test url connections on http> zz <- url("http://cran.r-project.org/")> readLines(zz)[1] "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">"[2] ""[3] "<html>"[4] "<head>"[5] "<title>The Comprehensive R Archive Network</title>"[6] "<link rel=\"icon\" href=\"favicon.ico\" type=\"image/x-icon\">"[7] "<link rel=\"shortcut icon\" href=\"favicon.ico\" type=\"image/x-icon\">"[8] "<link rel=\"stylesheet\" type=\"text/css\" href=\"R.css\">"[9] "</head>"[10] ""[11] "<FRAMESET cols=\"1*, 4*\" border=0>"[12] "<FRAMESET rows=\"120, 1*\">"[13] "<FRAME src=\"logo.html\" name=\"logo\" frameborder=0>"[14] "<FRAME src=\"navbar.html\" name=\"contents\" frameborder=0>"[15] "</FRAMESET>"[16] "<FRAME src=\"banner.shtml\" name=\"banner\" frameborder=0>"[17] "<noframes>"[18] "<h1>The Comprehensive R Archive Network</h1>"[19] ""[20] "Your browser seems not to support frames,"[21] "here is the <A href=\"navbar.html\">contents page</A> of CRAN."[22] "</noframes>"[23] "</FRAMESET>"[24] ""[25] ""[26] ""> close(zz)>> ## check graceful failure:> try(zz <- url("http://foo.bar", "r"))Error in url("http://foo.bar", "r") : cannot open the connectionIn addition: Warning message:In url("http://foo.bar", "r") : unable to resolve 'foo.bar'>> # and via read.table, test http and ftp.>> read.table("http://www.stats.ox.ac.uk/pub/datasets/csb/ch11b.dat")V1 V2 V3 V4 V51 1 307 930 36.58 02 2 307 940 36.73 03 3 307 950 36.93 04 4 307 1000 37.15 05 5 307 1010 37.23 06 6 307 1020 37.24 07 7 307 1030 37.24 08 8 307 1040 36.90 09 9 307 1050 36.95 010 10 307 1100 36.89 011 11 307 1110 36.95 012 12 307 1120 37.00 013 13 307 1130 36.90 014 14 307 1140 36.99 015 15 307 1150 36.99 016 16 307 1200 37.01 017 17 307 1210 37.04 018 18 307 1220 37.04 019 19 307 1230 37.14 020 20 307 1240 37.07 021 21 307 1250 36.98 022 22 307 1300 37.01 023 23 307 1310 36.97 024 24 307 1320 36.97 025 25 307 1330 37.12 026 26 307 1340 37.13 027 27 307 1350 37.14 028 28 307 1400 37.15 029 29 307 1410 37.17 030 30 307 1420 37.12 031 31 307 1430 37.12 032 32 307 1440 37.17 033 33 307 1450 37.28 034 34 307 1500 37.28 035 35 307 1510 37.44 036 36 307 1520 37.51 037 37 307 1530 37.64 038 38 307 1540 37.51 039 39 307 1550 37.98 140 40 307 1600 38.02 141 41 307 1610 38.00 142 42 307 1620 38.24 143 43 307 1630 38.10 144 44 307 1640 38.24 145 45 307 1650 38.11 146 46 307 1700 38.02 147 47 307 1710 38.11 148 48 307 1720 38.01 149 49 307 1730 37.91 150 50 307 1740 37.96 151 51 307 1750 38.03 152 52 307 1800 38.17 153 53 307 1810 38.19 154 54 307 1820 38.18 155 55 307 1830 38.15 156 56 307 1840 38.04 157 57 307 1850 37.96 158 58 307 1900 37.84 159 59 307 1910 37.83 160 60 307 1920 37.84 161 61 307 1930 37.74 162 62 307 1940 37.76 163 63 307 1950 37.76 164 64 307 2000 37.64 165 65 307 2010 37.63 166 66 307 2020 38.06 167 67 307 2030 38.19 168 68 307 2040 38.35 169 69 307 2050 38.25 170 70 307 2100 37.86 171 71 307 2110 37.95 172 72 307 2120 37.95 173 73 307 2130 37.76 174 74 307 2140 37.60 175 75 307 2150 37.89 176 76 307 2200 37.86 177 77 307 2210 37.71 178 78 307 2220 37.78 179 79 307 2230 37.82 180 80 307 2240 37.76 181 81 307 2250 37.81 182 82 307 2300 37.84 183 83 307 2310 38.01 184 84 307 2320 38.10 185 85 307 2330 38.15 186 86 307 2340 37.92 187 87 307 2350 37.64 188 88 308 0 37.70 189 89 308 10 37.46 190 90 308 20 37.41 191 91 308 30 37.46 192 92 308 40 37.56 193 93 308 50 37.55 194 94 308 100 37.75 195 95 308 110 37.76 196 96 308 120 37.73 197 97 308 130 37.77 198 98 308 140 38.01 199 99 308 150 38.04 1100 100 308 200 38.07 1> read.table("ftp://ftp.stats.ox.ac.uk/pub/datasets/csb/ch11b.dat")V1 V2 V3 V4 V51 1 307 930 36.58 02 2 307 940 36.73 03 3 307 950 36.93 04 4 307 1000 37.15 05 5 307 1010 37.23 06 6 307 1020 37.24 07 7 307 1030 37.24 08 8 307 1040 36.90 09 9 307 1050 36.95 010 10 307 1100 36.89 011 11 307 1110 36.95 012 12 307 1120 37.00 013 13 307 1130 36.90 014 14 307 1140 36.99 015 15 307 1150 36.99 016 16 307 1200 37.01 017 17 307 1210 37.04 018 18 307 1220 37.04 019 19 307 1230 37.14 020 20 307 1240 37.07 021 21 307 1250 36.98 022 22 307 1300 37.01 023 23 307 1310 36.97 024 24 307 1320 36.97 025 25 307 1330 37.12 026 26 307 1340 37.13 027 27 307 1350 37.14 028 28 307 1400 37.15 029 29 307 1410 37.17 030 30 307 1420 37.12 031 31 307 1430 37.12 032 32 307 1440 37.17 033 33 307 1450 37.28 034 34 307 1500 37.28 035 35 307 1510 37.44 036 36 307 1520 37.51 037 37 307 1530 37.64 038 38 307 1540 37.51 039 39 307 1550 37.98 140 40 307 1600 38.02 141 41 307 1610 38.00 142 42 307 1620 38.24 143 43 307 1630 38.10 144 44 307 1640 38.24 145 45 307 1650 38.11 146 46 307 1700 38.02 147 47 307 1710 38.11 148 48 307 1720 38.01 149 49 307 1730 37.91 150 50 307 1740 37.96 151 51 307 1750 38.03 152 52 307 1800 38.17 153 53 307 1810 38.19 154 54 307 1820 38.18 155 55 307 1830 38.15 156 56 307 1840 38.04 157 57 307 1850 37.96 158 58 307 1900 37.84 159 59 307 1910 37.83 160 60 307 1920 37.84 161 61 307 1930 37.74 162 62 307 1940 37.76 163 63 307 1950 37.76 164 64 307 2000 37.64 165 65 307 2010 37.63 166 66 307 2020 38.06 167 67 307 2030 38.19 168 68 307 2040 38.35 169 69 307 2050 38.25 170 70 307 2100 37.86 171 71 307 2110 37.95 172 72 307 2120 37.95 173 73 307 2130 37.76 174 74 307 2140 37.60 175 75 307 2150 37.89 176 76 307 2200 37.86 177 77 307 2210 37.71 178 78 307 2220 37.78 179 79 307 2230 37.82 180 80 307 2240 37.76 181 81 307 2250 37.81 182 82 307 2300 37.84 183 83 307 2310 38.01 184 84 307 2320 38.10 185 85 307 2330 38.15 186 86 307 2340 37.92 187 87 307 2350 37.64 188 88 308 0 37.70 189 89 308 10 37.46 190 90 308 20 37.41 191 91 308 30 37.46 192 92 308 40 37.56 193 93 308 50 37.55 194 94 308 100 37.75 195 95 308 110 37.76 196 96 308 120 37.73 197 97 308 130 37.77 198 98 308 140 38.01 199 99 308 150 38.04 1100 100 308 200 38.07 1>> ## everything from here on is directly over sockets> if(!capabilities("sockets")) stop("no socket capabilities")>> # do the same thing via sockets (cut-down httpclient)> httpget <- function (url, port = 80)+ {+ urlel <- strsplit(url, "/")[[1]]+ if (urlel[1] != "http:") stop("Not an http:// URL")+ host <- urlel[3]+ rurl <- paste(c("", urlel[-(1:3)]), collapse = "/")+ a <- make.socket(host, port = port)+ on.exit(close.socket(a))+ headreq <- paste("HEAD", rurl, "HTTP/1.0\r\nConnection: Keep-Alive\r\nAccept: text/plain\r\n\r\n")+ write.socket(a, headreq)+ head <- read.socket(a, maxlen = 8000)+ b <- strsplit(head, "\n")[[1]]+ if (length(grep("200 OK", b[1])) == 0) stop(b[1])+ len <- as.numeric(strsplit(grep("Content-Length", b, value = TRUE),+ ":")[[1]][2])+ getreq <- paste("GET", rurl, "HTTP/1.0\r\nConnection: Keep-Alive\r\nAccept: text/plain\r\n\r\n")+ write.socket(a, getreq)+ junk <- read.socket(a, maxlen = nchar(head))+ data <- ""+ b <- strsplit(c(head, junk), "\n")+ nn <- length(b[[1]])+ if (length(b[[2]]) > nn)+ data <- paste(b[[2]][-(1:nn)], collapse = "\n")+ while (nchar(data) < len) {+ data <- paste(data, read.socket(a, maxlen = len - nchar(data)),+ sep = "")+ }+ strsplit(data, "\n")[[1]]+ }>> if(nchar(Sys.getenv("http_proxy")) > 0+ || nchar(Sys.getenv("HTTP_PROXY")) > 0) {+ cat("http proxy is set, so skip test of http over sockets\n")+ } else {+ httpget("http://www.stats.ox.ac.uk/pub/datasets/csb/ch11b.dat")+ }[1] "001 307 0930 36.58 0" "002 307 0940 36.73 0" "003 307 0950 36.93 0"[4] "004 307 1000 37.15 0" "005 307 1010 37.23 0" "006 307 1020 37.24 0"[7] "007 307 1030 37.24 0" "008 307 1040 36.90 0" "009 307 1050 36.95 0"[10] "010 307 1100 36.89 0" "011 307 1110 36.95 0" "012 307 1120 37.00 0"[13] "013 307 1130 36.90 0" "014 307 1140 36.99 0" "015 307 1150 36.99 0"[16] "016 307 1200 37.01 0" "017 307 1210 37.04 0" "018 307 1220 37.04 0"[19] "019 307 1230 37.14 0" "020 307 1240 37.07 0" "021 307 1250 36.98 0"[22] "022 307 1300 37.01 0" "023 307 1310 36.97 0" "024 307 1320 36.97 0"[25] "025 307 1330 37.12 0" "026 307 1340 37.13 0" "027 307 1350 37.14 0"[28] "028 307 1400 37.15 0" "029 307 1410 37.17 0" "030 307 1420 37.12 0"[31] "031 307 1430 37.12 0" "032 307 1440 37.17 0" "033 307 1450 37.28 0"[34] "034 307 1500 37.28 0" "035 307 1510 37.44 0" "036 307 1520 37.51 0"[37] "037 307 1530 37.64 0" "038 307 1540 37.51 0" "039 307 1550 37.98 1"[40] "040 307 1600 38.02 1" "041 307 1610 38.00 1 " "042 307 1620 38.24 1 "[43] "043 307 1630 38.10 1" "044 307 1640 38.24 1" "045 307 1650 38.11 1"[46] "046 307 1700 38.02 1" "047 307 1710 38.11 1" "048 307 1720 38.01 1"[49] "049 307 1730 37.91 1" "050 307 1740 37.96 1" "051 307 1750 38.03 1"[52] "052 307 1800 38.17 1" "053 307 1810 38.19 1" "054 307 1820 38.18 1"[55] "055 307 1830 38.15 1" "056 307 1840 38.04 1" "057 307 1850 37.96 1"[58] "058 307 1900 37.84 1" "059 307 1910 37.83 1" "060 307 1920 37.84 1"[61] "061 307 1930 37.74 1" "062 307 1940 37.76 1" "063 307 1950 37.76 1"[64] "064 307 2000 37.64 1" "065 307 2010 37.63 1" "066 307 2020 38.06 1"[67] "067 307 2030 38.19 1" "068 307 2040 38.35 1" "069 307 2050 38.25 1"[70] "070 307 2100 37.86 1" "071 307 2110 37.95 1" "072 307 2120 37.95 1"[73] "073 307 2130 37.76 1" "074 307 2140 37.60 1" "075 307 2150 37.89 1"[76] "076 307 2200 37.86 1" "077 307 2210 37.71 1" "078 307 2220 37.78 1"[79] "079 307 2230 37.82 1" "080 307 2240 37.76 1" "081 307 2250 37.81 1"[82] "082 307 2300 37.84 1" "083 307 2310 38.01 1" "084 307 2320 38.10 1"[85] "085 307 2330 38.15 1" "086 307 2340 37.92 1" "087 307 2350 37.64 1"[88] "088 308 0000 37.70 1" "089 308 0010 37.46 1" "090 308 0020 37.41 1"[91] "091 308 0030 37.46 1" "092 308 0040 37.56 1" "093 308 0050 37.55 1"[94] "094 308 0100 37.75 1" "095 308 0110 37.76 1" "096 308 0120 37.73 1"[97] "097 308 0130 37.77 1" "098 308 0140 38.01 1" "099 308 0150 38.04 1"[100] "100 308 0200 38.07 1">> finger <- function(user, host = "localhost", port = 79, print = TRUE)+ {+ if (!is.character(user))+ stop("user name must be a string")+ user <- paste(user,"\r\n")+ socket <- make.socket(host, port)+ on.exit(close.socket(socket))+ write.socket(socket, user)+ output <- character(0)+ repeat{+ ss <- read.socket(socket)+ if (ss == "") break+ output <- paste(output, ss)+ }+ close.socket(socket)+ if (print) cat(output)+ invisible(output)+ }> try(finger("root")) ## only works if your site provides a finger daemonError in make.socket(host, port) : socket not established>