diff --git a/DESCRIPTION b/DESCRIPTION index fe00f0e..bfe941f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,14 +3,17 @@ Type: Package Title: filemagic title goes here Version: 0.1.0 Date: 2016-08-12 -Author: Bob Rudis (@hrbrmstr) +Author: Bob Rudis (@hrbrmstr), Christos Zoulas [libmagic] Maintainer: Bob Rudis Description: filemagic description goes here URL: http://github.com/hrbrmstr/filemagic BugReports: https://github.com/hrbrmstr/filemagic/issues License: AGPL Suggests: - testthat + testthat, + tibble, + magrittr, + dplyr Depends: R (>= 3.0.0) Imports: diff --git a/NAMESPACE b/NAMESPACE index cb70fab..e21a9bb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ # Generated by roxygen2: do not edit by hand -export(get_mimetype) +export(incant) import(purrr) importFrom(Rcpp,sourceCpp) useDynLib(filemagic) diff --git a/R/RcppExports.R b/R/RcppExports.R index 3fbf320..6449e9c 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -3,8 +3,18 @@ #' Return file info #' +#' @param path character vector of files to use magic on +#' @return a \code{tibble} / \code{data.frame} of file magic attributes #' @export -get_mimetype <- function(path) { - .Call('filemagic_get_mimetype', PACKAGE = 'filemagic', path) +#' @examples +#' library(magrittr) +#' library(dplyr) +#' +#' system.file("img", package="filemagic") %>% +#' list.files(full.names=TRUE) %>% +#' incant() %>% +#' glimpse() +incant <- function(path) { + .Call('filemagic_incant', PACKAGE = 'filemagic', path) } diff --git a/README.Rmd b/README.Rmd index 12b6466..b73fb5c 100644 --- a/README.Rmd +++ b/README.Rmd @@ -2,11 +2,13 @@ output: rmarkdown::github_document --- -`filemagic` : R interface to libmagic +`filemagic` : R interface to `libmagic` + +So you do need to install `libmagic` to use this. This should also be pretty straightforward to get working on Windows. Assistance to do that is welcome. The following functions are implemented: -- `get_mimetype` : returns the mimetype of the files in the input vector (as a data frame) +- `incant` : returns the mimetype of the files in the input vector (as a data frame) The following data sets are included: @@ -24,8 +26,15 @@ options(width=120) ### Usage -```{r} +```{r message=FALSE} library(filemagic) +library(magrittr) +library(dplyr) + +system.file("img", package="filemagic") %>% + list.files(full.names=TRUE) %>% + incant() %>% + glimpse() # current verison packageVersion("filemagic") diff --git a/README.md b/README.md index 95ef6bb..3381757 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ -`filemagic` : R interface to libmagic +`filemagic` : R interface to `libmagic` + +So you do need to install `libmagic` to use this. This should also be pretty straightforward to get working on Windows. Assistance to do that is welcome. The following functions are implemented: -- `get_mimetype` : returns the mimetype of the files in the input vector (as a data frame) +- `incant` : returns the mimetype of the files in the input vector (as a data frame) The following data sets are included: @@ -19,7 +21,24 @@ devtools::install_github("hrbrmstr/filemagic") ``` r library(filemagic) +library(magrittr) +library(dplyr) + +system.file("img", package="filemagic") %>% + list.files(full.names=TRUE) %>% + incant() %>% + glimpse() +``` + + ## Observations: 10 + ## Variables: 5 + ## $ file "/Library/Frameworks/R.framework/Versions/3.3/Resources/library/filemagic/img/example_dir", "/L... + ## $ mime_type "inode/directory", "text/x-c", "text/html", "text/plain", "text/rtf", "image/jpeg", "applicatio... + ## $ encoding "binary", "us-ascii", "us-ascii", "us-ascii", "us-ascii", "binary", "binary", "binary", "us-asc... + ## $ extensions NA, "???", "???", "???", "???", "jpeg/jpg/jpe/jfif", "???", "???", "???", "???" + ## $ description "directory", "C source, ASCII text", "HTML document, ASCII text, with CRLF line terminators", "... +``` r # current verison packageVersion("filemagic") ``` @@ -31,11 +50,24 @@ packageVersion("filemagic") ``` r library(filemagic) library(testthat) +``` + ## + ## Attaching package: 'testthat' + + ## The following object is masked from 'package:dplyr': + ## + ## matches + + ## The following objects are masked from 'package:magrittr': + ## + ## equals, is_less_than, not + +``` r date() ``` - ## [1] "Fri Aug 12 18:16:56 2016" + ## [1] "Fri Aug 12 19:41:08 2016" ``` r test_dir("tests/") diff --git a/inst/img/Rlogo.jpg b/inst/img/Rlogo.jpg new file mode 100644 index 0000000..6d33489 Binary files /dev/null and b/inst/img/Rlogo.jpg differ diff --git a/inst/img/Rlogo.pdf b/inst/img/Rlogo.pdf new file mode 100644 index 0000000..616dbaa Binary files /dev/null and b/inst/img/Rlogo.pdf differ diff --git a/inst/img/Rlogo.png b/inst/img/Rlogo.png new file mode 100644 index 0000000..fba5412 Binary files /dev/null and b/inst/img/Rlogo.png differ diff --git a/inst/img/Rlogo.svg b/inst/img/Rlogo.svg new file mode 100644 index 0000000..78281f7 --- /dev/null +++ b/inst/img/Rlogo.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/inst/img/Rlogo.tiff b/inst/img/Rlogo.tiff new file mode 100644 index 0000000..b8d4c99 Binary files /dev/null and b/inst/img/Rlogo.tiff differ diff --git a/inst/img/example.c b/inst/img/example.c new file mode 100644 index 0000000..aecf6ff --- /dev/null +++ b/inst/img/example.c @@ -0,0 +1,5 @@ +#include + +void main() { + +} \ No newline at end of file diff --git a/inst/img/example.html b/inst/img/example.html new file mode 100644 index 0000000..2626429 --- /dev/null +++ b/inst/img/example.html @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/inst/img/example.r b/inst/img/example.r new file mode 100644 index 0000000..bd5fe68 --- /dev/null +++ b/inst/img/example.r @@ -0,0 +1 @@ +print("examle") \ No newline at end of file diff --git a/inst/img/example.rtf b/inst/img/example.rtf new file mode 100644 index 0000000..40eb646 --- /dev/null +++ b/inst/img/example.rtf @@ -0,0 +1,5 @@ +{\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf470 +{\fonttbl} +{\colortbl;\red255\green255\blue255;} +\margl1440\margr1440\vieww12540\viewh14960\viewkind1 +} \ No newline at end of file diff --git a/man/get_mimetype.Rd b/man/get_mimetype.Rd deleted file mode 100644 index 2141f3f..0000000 --- a/man/get_mimetype.Rd +++ /dev/null @@ -1,12 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/RcppExports.R -\name{get_mimetype} -\alias{get_mimetype} -\title{Return file info} -\usage{ -get_mimetype(path) -} -\description{ -Return file info -} - diff --git a/man/incant.Rd b/man/incant.Rd new file mode 100644 index 0000000..e3fb999 --- /dev/null +++ b/man/incant.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RcppExports.R +\name{incant} +\alias{incant} +\title{Return file info} +\usage{ +incant(path) +} +\arguments{ +\item{path}{character vector of files to use magic on} +} +\value{ +a \code{tibble} / \code{data.frame} of file magic attributes +} +\description{ +Return file info +} +\examples{ +library(magrittr) +library(dplyr) + +system.file("img", package="filemagic") \%>\% + list.files(full.names=TRUE) \%>\% + incant() \%>\% + glimpse() +} + diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 0977b54..3ec15e2 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -5,14 +5,14 @@ using namespace Rcpp; -// get_mimetype -DataFrame get_mimetype(CharacterVector path); -RcppExport SEXP filemagic_get_mimetype(SEXP pathSEXP) { +// incant +DataFrame incant(CharacterVector path); +RcppExport SEXP filemagic_incant(SEXP pathSEXP) { BEGIN_RCPP Rcpp::RObject __result; Rcpp::RNGScope __rngScope; Rcpp::traits::input_parameter< CharacterVector >::type path(pathSEXP); - __result = Rcpp::wrap(get_mimetype(path)); + __result = Rcpp::wrap(incant(path)); return __result; END_RCPP } diff --git a/src/filemagic.cpp b/src/filemagic.cpp index e8937ba..447cfd9 100644 --- a/src/filemagic.cpp +++ b/src/filemagic.cpp @@ -6,12 +6,25 @@ using namespace Rcpp; //' Return file info //' +//' @param path character vector of files to use magic on +//' @return a \code{tibble} / \code{data.frame} of file magic attributes //' @export +//' @examples +//' library(magrittr) +//' library(dplyr) +//' +//' system.file("img", package="filemagic") %>% +//' list.files(full.names=TRUE) %>% +//' incant() %>% +//' glimpse() // [[Rcpp::export]] -DataFrame get_mimetype(CharacterVector path) { +DataFrame incant(CharacterVector path) { unsigned int input_size = path.size(); StringVector mime_type(input_size); + StringVector encoding(input_size); + StringVector extensions(input_size); + StringVector description(input_size); for (unsigned int i=0; i