1

On occasion, I have a spotty internet connection or a severely reduced internet connection and I would like to automate web scraping activities. Often times I download files with R, ranging from very small size to several GB. Obviously, if you have a reduced internet connection speed, larger files will take a very long time to download. It would be useful to have this information in R, as a check for proceeding with webscraping.

I'd like to create a script or function in R that is capable of outputting an average internet speed. Is this possible?

I've seen threads that allow you to determine if you have an active internet connection in R. They seem to employ ideas of testing for an internet connection using the RCurl::getURL or they use system calls for ipconfig. One person also found a solution using DNS lookup.

Community
  • 1
  • 1
IRNotSmart
  • 351
  • 6
  • 18
  • (a) what OS do you run? (b) do you have a server you can run a process on? (c) are you ok with a `system()` call to another script? – hrbrmstr Apr 12 '17 at 00:21
  • a) Windows 7, b) I do not have a server, c) I could be ok with a `system()`call from R, but the reason for my post is to find any and all ways to achieve a possible speed test. I assume a system call could accomplish this, but are there other ways? – IRNotSmart Apr 12 '17 at 05:25

2 Answers2

3

If you are happy with latency then I would suggest using ping:

install.packages(pingr)
library(pingr)
lolz<-ping("132.204.3.57")

You can use if (lolz < 60) { download(...) } before you download command to avoid downloading when your ping to the server hosting the files is terrible.

Julian Wittische
  • 1,219
  • 14
  • 22
  • 1
    Testing with ICMP packets or small TCP packets (for the port-versions of functions in `pingr` is not going to provide representative data for actual downloads). – hrbrmstr Apr 12 '17 at 00:19
1

The package {speedtest} can do tha for you. It is currently under development.

# install package
install.packages("speedtest", repos = "https://cinc.rud.is")
library(speedtest)
library(pingr)

# test speed
speedtest::spd_test()
rafa.pereira
  • 13,251
  • 6
  • 71
  • 109