This will download a file and source it. Because it uses the
download() function, it can handle https URLs.
The URL to download.
A SHA-1 hash of the file at the URL.
Other arguments that are passed to
Prompt the user if no value for
source_url() checks the SHA-1 hash of the file. If it
differs from the expected value, it will throw an error. The default
expectation is that a hash is provided; if not,
prompt the user, asking if they are sure they want to continue, unless
prompt=FALSE is used. In other words, if you use
it will run the remote code without checking the hash, and without asking
The purpose of checking the hash is to ensure that the file has not changed.
source_url command with a hash is posted in a public forum, then
others who source the URL (with the hash) are guaranteed to run the same
code every time. This means that the author doesn't need to worry about the
security of the server hosting the file. It also means that the users don't
have to worry about the file being replaced with a damaged or
To find the hash of a local file, use
digest(). For a simple
way to find the hash of a remote file, use
1 2 3 4 5 6 7 8 9 10 11 12 13 14
## Not run: # Source the a sample file # This is a very long URL; break it up so it can be seen more easily in the # examples. test_url <- paste0("https://gist.github.com/wch/dae7c106ee99fe1fdfe7", "/raw/db0c9bfe0de85d15c60b0b9bf22403c0f5e1fb15/test.r") downloader::source_url(test_url, sha = "9b8ff5213e32a871d6cb95cce0bed35c53307f61") # Find the hash of a file downloader::sha_url(test_url) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.