You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.8 KiB

8 years ago
---
output: rmarkdown::github_document
---
8 years ago
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/0.1.0/active.svg)](http://www.repostatus.org/#active)
[![Travis-CI Build Status](https://travis-ci.org/hrbrmstr/wand.svg?branch=master)](https://travis-ci.org/hrbrmstr/wand)
8 years ago
8 years ago
`wand` : Retrieve 'Magic' Attributes from Files and Directories
8 years ago
The `libmagic` library must be installed on *nix/macOS and available to use this.
8 years ago
8 years ago
- `apt-get install libmagic-dev` on Ubuntu/Debian-ish systems
8 years ago
- `brew install libmagic` on macOS
8 years ago
- `yum install file-devel` on RHEL/CentOS/Fedora
8 years ago
8 years ago
While the package was developed using the 5.28 version of `libmagic` it has been configured to work with older versions. Note that some fields in the resultant data frame might not be available with older library versions. When using the function `magic_wand_file()` it checks for which version of `libmagic` is installed on your system and provides a suitable `magic.mgc` file for it.
8 years ago
8 years ago
The package also works on Windows but it's a bit of a hack because, well, _Windows_. The Windows version makes two `system2()` calls and relies on `Rtools` being installed and `file.exe` being available on the Windows `PATH`, so it's sub-optimal at best. Help to get it working in C would be greatly appreciated. Windows folk can go [here](https://github.com/stan-dev/rstan/wiki/Install-Rtools-for-Windows) to find out more info on `Rtools`.
8 years ago
The following functions are implemented:
8 years ago
- `incant` : returns the "magic" metadata of the files in the input vector (as a data frame)
- `magic_wand_file` : provides a full path to the package-provided `magic` file
8 years ago
8 years ago
The following datasets are included:
- `mime_db` : a database of all mime types from <https://github.com/jshttp/mime-db>
8 years ago
### Installation
```{r eval=FALSE}
8 years ago
devtools::install_github("hrbrmstr/wand")
8 years ago
```
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width=120)
```
### Usage
```{r message=FALSE}
8 years ago
library(wand)
library(dplyr)
8 years ago
system.file("extdata", "img", package="wand") %>%
list.files(full.names=TRUE) %>%
incant() %>%
glimpse()
8 years ago
```
8 years ago
8 years ago
```{r message=FALSE}
# Use a non-system magic-file
8 years ago
system.file("extdata", "img", package="wand") %>%
list.files(full.names=TRUE) %>%
incant(magic_wand_file()) %>%
select(description) %>%
unlist(use.names=FALSE)
8 years ago
```
8 years ago
```{r message=FALSE}
# what kinds of extensions are associated with these mime types
system.file("extdata", "img", package="wand") %>%
list.files(full.names=TRUE) %>%
incant(magic_wand_file()) %>%
select(extensions) %>%
as.data.frame()
```
```{r message=FALSE}
8 years ago
# current verison
8 years ago
packageVersion("wand")
8 years ago
```
### Test Results
8 years ago
```{r message=FALSE}
8 years ago
library(wand)
8 years ago
library(testthat)
date()
test_dir("tests/")
```