Browse Source

find_dsstore() & passes CRAN checks

master
boB Rudis 6 years ago
parent
commit
53e53456b0
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 1
      .Rbuildignore
  2. 7
      NAMESPACE
  3. 59
      R/find-dsstore.R
  4. 5
      R/mactheknife-package.R
  5. 2
      R/su-hist-file.R
  6. 2
      README.Rmd
  7. 37
      README.md
  8. 27
      man/find_dsstore.Rd

1
.Rbuildignore

@ -7,5 +7,6 @@
^NOTES\.*html$
^\.codecov\.yml$
^README_files$
^README_cache$
^doc$
^tmp$

7
NAMESPACE

@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand
export(airport_scan)
export(find_dsstore)
export(kernel_state)
export(read_dsstore)
export(software_update_history)
@ -14,5 +15,11 @@ importFrom(purrr,"%>%")
importFrom(purrr,flatten_chr)
importFrom(purrr,map_chr)
importFrom(purrr,map_df)
importFrom(purrr,map_lgl)
importFrom(purrr,safely)
importFrom(purrr,set_names)
importFrom(stats,complete.cases)
importFrom(utils,compareVersion)
importFrom(utils,download.file)
importFrom(utils,read.fwf)
importFrom(utils,type.convert)

59
R/find-dsstore.R

@ -0,0 +1,59 @@
.s_unlink <- purrr::safely(unlink)
#' Find and optionally remove `.DS_Store` files on a locally-accessible filesystem
#'
#' Provide a starting point, recursion option (similar to [list.files()]) &
#' whether or not to remove any `.DS_Store` files found and
#' get back a data frame of full paths to any `.DS_Store` files that exist
#' or were removed. The removal success status (if `remove` is `TRUE` will be added
#' as a column to the data frame).\cr\cr
#' If no `.DS_Store` files were found, an empty data frame is returned.
#'
#' @md
#' @param path a character vector of full path names; the default corresponds to
#' the working directory, [getwd()]. Tilde expansion (see [path.expand()])
#' is performed. Missing values will be ignored.
#' @param recursive logical. Should the listing recurse into directories? Default is `FALSE`.
#' @param remove if `TRUE` the function will attempt to [unlink()] any `.DS_Store`
#' files found. Permissions issue may cause this option to fail to delete
#' found `.DS_Store` files. Default: `FALSE`
#' @export
find_dsstore <- function(path = ".", recursive = FALSE, remove = FALSE) {
list.files(
path = path,
pattern = "\\.DS_Store",
all.files = TRUE,
full.names = TRUE,
recursive = recursive
) -> fils
if (length(fils) > 0) {
data.frame(
path = fils,
stringsAsFactors=FALSE
) -> ret
if (remove) {
purrr::map_lgl(fils, ~{
res <- .s_unlink(.x, force = TRUE)
if (is.null(res$result)) return(FALSE)
return(res$result == 0)
}) -> rm_status
ret$removed <- rm_status
}
} else {
ret <- data.frame(stringsAsFactors=FALSE)
}
class(ret) <- c("tbl_df", "tbl", "data.frame")
ret
}

5
R/mactheknife-package.R

@ -7,7 +7,8 @@
#' @docType package
#' @author Bob Rudis (bob@@rud.is)
#' @import reticulate sys xml2
#' @importFrom purrr map_df %>% flatten_chr set_names map_chr
#' @importFrom purrr map_df %>% flatten_chr set_names map_chr safely map_lgl
#' @importFrom anytime anytime
#' @importFrom utils compareVersion
#' @importFrom stats complete.cases
#' @importFrom utils compareVersion download.file read.fwf type.convert
NULL

2
R/su-hist-file.R

@ -53,7 +53,7 @@ software_update_history <- function(su_hist_file = "/Library/Receipts/InstallHis
dat[j] <- as.list(val)
j <- j + 1
}
setNames(dat, keynms)
purrr::set_names(dat, keynms)
}) -> xdf
xdf[,c("displayName", "displayVersion", "date", "packageIdentifiers", "processName", "contentType")]

2
README.Rmd

@ -20,11 +20,11 @@ The following functions are implemented:
- `airport_scan`: Scan for available wireless network (requires Wi-Fi enabled Mac)
- `kernel_state`: Retrieve kernel state information
- `find_dsstore: Find and optionally remove '.DS_Store' files on a locally-accessible filesystem
- `read_dsstore`: Read a '.DS_Store' from a file/URL
- `software_update_history`: Retrieve Software Update history
- `sw_vers`: Retrieve macOS Operating System Version Information
## Installation
```{r eval=FALSE}

37
README.md

@ -21,6 +21,8 @@ The following functions are implemented:
- `airport_scan`: Scan for available wireless network (requires Wi-Fi
enabled Mac)
- `kernel_state`: Retrieve kernel state information
- \`find\_dsstore: Find and optionally remove ‘.DS\_Store’ files on a
locally-accessible filesystem
- `read_dsstore`: Read a ‘.DS\_Store’ from a file/URL
- `software_update_history`: Retrieve Software Update history
- `sw_vers`: Retrieve macOS Operating System Version Information
@ -104,40 +106,7 @@ list.files(
str(x)
```
## List of 33
## $ : chr [1:34] "2018-01-24-isds" "2018-cve-palooza" "2018-data-220g" "a-version" ...
## $ : chr [1:2] "R" "slides"
## $ : chr "2018-01-24-isds"
## $ : chr "data"
## $ : chr [1:6] "2018-data-220g.Rproj" "docs" "README.md" "README.Rmd" ...
## $ : chr "week01"
## $ : chr(0)
## $ : chr(0)
## $ : chr "data"
## $ : chr(0)
## $ : chr(0)
## $ : chr "data"
## $ : chr "data"
## $ : chr "data"
## $ : chr(0)
## $ : chr "sugrrants-0.1.0"
## $ : chr "data"
## $ : chr "packrat"
## $ : chr [1:4] "lib" "lib-ext" "lib-R" "src"
## $ : chr "x86_64-apple-darwin15.6.0"
## $ : chr "3.4.0"
## $ : chr(0)
## $ : chr "data"
## $ : chr "test"
## $ : chr [1:2] "lists" "threat-docs"
## $ : chr(0)
## $ : chr "2017q2-threat-report"
## $ : chr "data"
## $ : chr [1:2] "q2-threatintelreport-rdpdata.csv" "q2-threatintelreport-smbdata.csv"
## $ : chr "data"
## $ : chr "sports-time-of-day"
## $ : chr "data"
## $ : chr "data"
## list()
### “Software Update” History

27
man/find_dsstore.Rd

@ -0,0 +1,27 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/find-dsstore.R
\name{find_dsstore}
\alias{find_dsstore}
\title{Find and optionally remove \code{.DS_Store} files on a locally-accessible filesystem}
\usage{
find_dsstore(path = ".", recursive = FALSE, remove = FALSE)
}
\arguments{
\item{path}{a character vector of full path names; the default corresponds to
the working directory, \code{\link[=getwd]{getwd()}}. Tilde expansion (see \code{\link[=path.expand]{path.expand()}})
is performed. Missing values will be ignored.}
\item{recursive}{logical. Should the listing recurse into directories? Default is \code{FALSE}.}
\item{remove}{if \code{TRUE} the function will attempt to \code{\link[=unlink]{unlink()}} any \code{.DS_Store}
files found. Permissions issue may cause this option to fail to delete
found \code{.DS_Store} files. Default: \code{FALSE}}
}
\description{
Provide a starting point, recursion option (similar to \code{\link[=list.files]{list.files()}}) &
whether or not to remove any \code{.DS_Store} files found and
get back a data frame of full paths to any \code{.DS_Store} files that exist
or were removed. The removal success status (if \code{remove} is \code{TRUE} will be added
as a column to the data frame).\cr\cr
If no \code{.DS_Store} files were found, an empty data frame is returned.
}
Loading…
Cancel
Save