diff --git a/R/RcppExports.R b/R/RcppExports.R index 5c05f39..d7908c1 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -1,10 +1,13 @@ # This file was generated by Rcpp::compileAttributes # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 -#' Return file info +#' Retrieve 'magic' attributes from files and directories #' #' @param path character vector of files to use magic on -#' @return a \code{tibble} / \code{data.frame} of file magic attributes +#' @return a \code{tibble} / \code{data.frame} of file magic attributes. +#' Specifically, mime type, encoding, possible file extensions and +#' type description are returned as colums in the data frame along +#' with \code{path}. #' @export #' @examples #' library(magrittr) diff --git a/man/incant.Rd b/man/incant.Rd index e3fb999..5fff68f 100644 --- a/man/incant.Rd +++ b/man/incant.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/RcppExports.R \name{incant} \alias{incant} -\title{Return file info} +\title{Retrieve 'magic' attributes from files and directories} \usage{ incant(path) } @@ -10,10 +10,13 @@ incant(path) \item{path}{character vector of files to use magic on} } \value{ -a \code{tibble} / \code{data.frame} of file magic attributes +a \code{tibble} / \code{data.frame} of file magic attributes. + Specifically, mime type, encoding, possible file extensions and + type description are returned as colums in the data frame along + with \code{path}. } \description{ -Return file info +Retrieve 'magic' attributes from files and directories } \examples{ library(magrittr) diff --git a/src/wand.cpp b/src/wand.cpp index 447cfd9..2e3f5dc 100644 --- a/src/wand.cpp +++ b/src/wand.cpp @@ -4,10 +4,13 @@ using namespace Rcpp; #include "magic.h" #include "limits.h" -//' Return file info +//' Retrieve 'magic' attributes from files and directories //' //' @param path character vector of files to use magic on -//' @return a \code{tibble} / \code{data.frame} of file magic attributes +//' @return a \code{tibble} / \code{data.frame} of file magic attributes. +//' Specifically, mime type, encoding, possible file extensions and +//' type description are returned as colums in the data frame along +//' with \code{path}. //' @export //' @examples //' library(magrittr) @@ -21,6 +24,7 @@ using namespace Rcpp; DataFrame incant(CharacterVector path) { unsigned int input_size = path.size(); + StringVector mime_type(input_size); StringVector encoding(input_size); StringVector extensions(input_size); @@ -35,7 +39,6 @@ DataFrame incant(CharacterVector path) { int flags = MAGIC_MIME_TYPE; magic_t cookie = magic_open(flags); - if (cookie == NULL) { mime_type[i] = NA_STRING; } else { @@ -95,11 +98,11 @@ DataFrame incant(CharacterVector path) { } } - DataFrame df = DataFrame::create(_["file"] = path, - _["mime_type"] = mime_type, - _["encoding"] = encoding, - _["extensions"] = extensions, - _["description"] = description, + DataFrame df = DataFrame::create(_["file"] = path, + _["mime_type"] = mime_type, + _["encoding"] = encoding, + _["extensions"] = extensions, + _["description"] = description, _["stringsAsFactors"] = false); df.attr("class") = CharacterVector::create("tbl_df", "tbl", "data.frame");