Skip to contents

By default the file at the url origin is downloaded to the cache_dir ~/.keras, placed in the cache_subdir datasets, and given the filename fname. The final location of a file example.txt would therefore be ~/.keras/datasets/example.txt. Files in .tar, .tar.gz,, and .zip formats can also be extracted.

Passing a hash will verify the file after download. The command line programs shasum and sha256sum can compute the hash.


  fname = NULL,
  origin = NULL,
  file_hash = NULL,
  cache_subdir = "datasets",
  hash_algorithm = "auto",
  extract = FALSE,
  archive_format = "auto",
  cache_dir = NULL,
  force_download = FALSE



Name of the file. If an absolute path, e.g. "/path/to/file.txt" is specified, the file will be saved at that location. If NULL, the name of the file at origin will be used.


Original URL of the file.


For forward/backward compatability.


The expected hash string of the file after download. The sha256 and md5 hash algorithms are both supported.


Subdirectory under the Keras cache dir where the file is saved. If an absolute path, e.g. "/path/to/folder" is specified, the file will be saved at that location.


Select the hash algorithm to verify the file. options are "md5', "sha256', and "auto'. The default 'auto' detects the hash algorithm in use.


TRUE tries extracting the file as an Archive, like tar or zip.


Archive format to try for extracting the file. Options are "auto', "tar', "zip', and NULL. "tar" includes tar, tar.gz, and files. The default "auto" corresponds to c("tar", "zip"). NULL or an empty list will return no matches found.


Location to store cached files, when NULL it defaults to Sys.getenv("KERAS_HOME", "~/.keras/").


If TRUE, the file will always be re-downloaded regardless of the cache state.


Path to the downloaded file.

** Warning on malicious downloads **

Downloading something from the Internet carries a risk. NEVER download a file/archive if you do not trust the source. We recommend that you specify the file_hash argument (if the hash of the source file is known) to make sure that the file you are getting is the one you expect.


path_to_downloaded_file <- get_file(
    origin = "",
    extract = TRUE