Ad space (banner)
๐Ÿ“ŠR Lessons
Lesson 56 / 68

Pausing for a set time (Sys.sleep)

This lesson covers pausing with R's Sys.sleep, with the aim of understanding the basics of programs that deal with time.

Sys.sleep(seconds) pauses for the time you specify. Use it to space out calls to an API, or to slow work down deliberately.

The sample code prints "Starting", waits one second with Sys.sleep(1), and then prints "Ran after 1 second". Run it and you can feel the gap between the messages.

A common early stumble is the unit. Many languages take milliseconds; R takes seconds, which takes a moment to get used to.

In professional work, this is applied to waiting briefly before retrying, so as not to hammer a web API.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run R directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)