R/findCache.R

#########################################################################/**
# @RdocDefault findCache
#
# @title "Locates a cache file"
#
# \description{
#  @get "title" from a key object.
# }
#
# @synopsis
#
# \arguments{
#   \item{key}{An optional object from which a hexadecimal hash
#     code will be generated and appended to the filename.}
#   \item{...}{Additional argument passed to @see "generateCache".}
# }
#
# \value{
#   Returns the pathname as a @character, or @NULL if the no cached
#   data exists.
# }
#
# @author
#
# \seealso{
#  @see "generateCache".
#  @see "loadCache".
# }
#
# @keyword "programming"
# @keyword "IO"
# @keyword "internal"
#*/#########################################################################
setMethodS3("findCache", "default", function(key=NULL, ...) {
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  # Generate cache name from basename and hash object.
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  pathname <- generateCache(key=key, ...)

  if (file.exists(pathname) && !file.info(pathname)$isdir) {
    return(pathname)
  }

  pathnameT <- sprintf("%s.gz", pathname)
  if (file.exists(pathnameT) && !file.info(pathnameT)$isdir) {
    return(pathnameT)
  }

  return(NULL)
})

Try the R.cache package in your browser

Any scripts or data that you put into this service are public.

R.cache documentation built on July 21, 2022, 5:11 p.m.