12 changed files with 139 additions and 20 deletions
@ -1,6 +1,8 @@ |
|||
# Generated by roxygen2: do not edit by hand |
|||
|
|||
export(incant) |
|||
export(magic_wand_file) |
|||
import(purrr) |
|||
import(rappdirs) |
|||
importFrom(Rcpp,sourceCpp) |
|||
useDynLib(wand) |
|||
|
@ -0,0 +1,34 @@ |
|||
#' Use the "magic" file that comes with the package |
|||
#' |
|||
#' The \code{magic_load()} functon from \code{libmagic} can't take ZIP files |
|||
#' and the \code{magic.mgc} file that ships with the package is too large to |
|||
#' be shipped uncompressed. Using this function as the \code{magic_db} |
|||
#' parameter will copy and uncompress the database to a cache directory and |
|||
#' return the full path to the magic file. Subsequent calls will not have to |
|||
#' perform the decompression unless \code{force} is \code{TRUE} or the |
|||
#' cache directory has been cleared. |
|||
#' |
|||
#' @param force ensure the lastest copy of the pacakge "magic" |
|||
#' database is used. |
|||
#' @export |
|||
#' @examples |
|||
# ' library(magrittr) |
|||
# ' library(dplyr) |
|||
#' |
|||
#' system.file("img", package="filemagic") %>% |
|||
#' list.files(full.names=TRUE) %>% |
|||
#' incant(magic_wand_file()) %>% |
|||
#' glimpse() |
|||
magic_wand_file <- function(force=FALSE) { |
|||
|
|||
cache <- rappdirs::user_cache_dir("wandr") |
|||
|
|||
if (!dir.exists(cache)) dir.create(cache, showWarnings=FALSE) |
|||
if (!dir.exists(cache)) return("system") |
|||
|
|||
suppressWarnings(unzip(system.file("magic.mgc.zip", package="wand"), |
|||
exdir=cache, overwrite=force)) |
|||
|
|||
file.path(rappdirs::user_cache_dir("wandr"), "magic.mgc") |
|||
|
|||
} |
Binary file not shown.
@ -0,0 +1,31 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/zzz.r |
|||
\name{magic_wand_file} |
|||
\alias{magic_wand_file} |
|||
\title{Use the "magic" file that comes with the package} |
|||
\usage{ |
|||
magic_wand_file(force = FALSE) |
|||
} |
|||
\arguments{ |
|||
\item{force}{ensure the lastest copy of the pacakge "magic" |
|||
database is used.} |
|||
} |
|||
\description{ |
|||
The \code{magic_load()} functon from \code{libmagic} can't take ZIP files |
|||
and the \code{magic.mgc} file that ships with the package is too large to |
|||
be shipped uncompressed. Using this function as the \code{magic_db} |
|||
parameter will copy and uncompress the database to a cache directory and |
|||
return the full path to the magic file. Subsequent calls will not have to |
|||
perform the decompression unless \code{force} is \code{TRUE} or the |
|||
cache directory has been cleared. |
|||
} |
|||
\examples{ |
|||
library(magrittr) |
|||
library(dplyr) |
|||
|
|||
system.file("img", package="filemagic") \%>\% |
|||
list.files(full.names=TRUE) \%>\% |
|||
incant(magic_wand_file()) \%>\% |
|||
glimpse() |
|||
} |
|||
|
Loading…
Reference in new issue