Handy File and String Manipulation

This started out as a package for file and string manipulation. Since then, the 'fs' and 'strex' packages emerged, offering functionality previously given by this package (but slightly better). Those packages have hence almost pushed 'filesstrings' into extinction. However, it still has a small number of unique, handy file manipulation functions which can be seen in the vignette. One example is a function to remove spaces from all file names in a directory.


Convenient functions for moving files, deleting directories, and a variety of string operations that facilitate manipulating file names and extracting information from strings.

Travis-CI Build Status AppVeyor Build Status codecov CRAN_Status_Badge RStudio CRAN downloads RStudio CRAN monthly downloads Rdocumentation Project Status: Active – The project has reached a stable, usable state and is being actively developed. JOSS publication DOI

Installation

To install the release version (recommended) from CRAN, in R, enter

install.packages("filesstrings")

To install the development version, in R, first install devtools via install.packages("devtools"). Then enter

devtools::install_github("rorynolan/filesstrings")

Use

First let's load the library:

library(filesstrings)

Files

Move files around

I find it bizarre that base R has no file.move. To move a file, you have to unintuitively rename it. filesstrings provides file.move(files, destinations). This function has the nice feature that if you try to move files to a directory that doesn't exist, it creates the directory first and then puts the files inside. Let's create a directory and a file:

dir.create("tmp_dir")
file.create("tmp.txt")
#> [1] TRUE

Now let's put the file into the directory:

file.move("tmp.txt", "tmp_dir")
#> 1 file moved. 0 failed.

Delete Directories

To delete directories with base R, one has to use unlink(..., recursive = TRUE). The filesstrings package gives you dir.remove() which does the same job.

dir.remove("tmp_dir")
#> 1 directory deleted. 0 failed to delete.

Remove spaces from file names

"A space in your file name is a hole in your soul." - Jenny Bryan

remove_filename_spaces(replacement = "_") replaces them all with underscores for all files in a directory. By default, they are replaced with nothing.

file.create(c("file 1.txt", "file 2.txt"))
#> [1] TRUE TRUE
remove_filename_spaces(pattern = "txt$", replacement = "_")
#> 2 files renamed. 0 failed to rename.
list.files(pattern = "txt$")
#> [1] "file_1.txt" "file_2.txt"
file.remove(list.files(pattern = "txt$"))  # clean up
#> [1] TRUE TRUE

Strings

The nth number in a string

I often want to get the first, last or nth number in a string.

pop <- "A population of 1000 comprised of 488 dogs and 512 cats."
nth_number(pop, 1)
#> [1] 1000
nth_number(pop, -1)  # last number
#> [1] 512

All the numbers in a string

extract_numbers(pop)
#> [[1]]
#> [1] 1000  488  512

All the non-numbers in a string

extract_non_numerics(pop)
#> [[1]]
#> [1] "A population of " " comprised of "   " dogs and "      
#> [4] " cats."

Trim anything (not just whitespace)

stringr's str_trim just trims whitespace. What if you want to trim something else? Now you can trim_anything().

trim_anything("__rmarkdown_", "_")
#> [1] "rmarkdown"

Contribution

Contributions to this package are welcome. The preferred method of contribution is through a github pull request. Feel free to contact me by creating an issue. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

News

2.0.2

BUG FIXES

  • Fix to all_equal() for dealing with arrays.

2.0.1

BUG FIXES

  • The new R doesn't like it when the working directory is changed by running examples. This required a fix which this patch provides.

2.0.0

NEW FEATURES

  • Functions which were previously deprecated are now defunct. This brings the package completely in line with the tidyverse style.

MINOR IMPROVEMENTS

  • count_matches() and str_nth_instance_indices() are much faster.
  • merge_tables_on_disk() and paste_different_lengths() are gone. They didn't belong.

BUG FIXES

  • before_last_dot() now works in the case where the input has no dots, returning the input.

1.1.0

NEW FEATURES

  • Added first and last companions for nth functions.

MINOR IMPROVEMENTS

  • Minor documentation improvements.

1.1.0

NEW FEATURES

  • Everything has been redone to conform with the tidyverse style guide.

1.0.0

NEW FEATURES

  • The package is now peer-reviewed and has an accompanying paper in the journal of open-source software, which can be cited. See citation("filesstrings").

0.4.2

NEW FEATURES

  • The package now has the http://contributor-covenenant.org code of conduct.
  • The package now has the functions file.move() and dir.delete() to conform with the base naming pattern of such functions.

DEFUNCT

  • PutFilesInDir() is gone.

MINOR IMPROVEMENTS

  • The functionality that PutFilesInDir() had is now default for MoveFiles().
  • The README and vignettes are improved.

0.4.1

BUG FIXES

  • Minor fix to AllEqual().

0.4.0

BUG FIXES

  • Fix bug in AllEqual() and improve its documentation.
  • Improve NA handling of ExtractNumerics() and its documentation.

MINOR IMPROVEMENTS

  • Improve README and vignette.

0.3.2

BUG FIXES

  • A fix to make the package compatible with the new version of 'readr' courtesy of Jim Hester.

MINOR IMPROVEMENTS

  • Minor documentation improvements.

DEFUNCT

  • StrReverse() is removed. Use stringi::stri_reverse() instead.

0.3.1

BUG FIXES

filesstrings 0.3.0

  • The first edition that I think may be CRAN-worthy.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("filesstrings")

2.7.0 by Rory Nolan, 2 months ago


https://www.github.com/rorynolan/filesstrings


Report a bug at https://www.github.com/rorynolan/filesstrings/issues


Browse source code at https://github.com/cran/filesstrings


Authors: Rory Nolan [aut, cre, cph] , Sergi Padilla-Parra [ths]


Documentation:   PDF Manual  


GPL-3 license


Imports magrittr, tools, purrr, checkmate, strex, matrixStats, Rcpp, ore, tibble, rlang

Depends on stringr

Suggests testthat, covr, knitr, rmarkdown, spelling

Linking to Rcpp


Imported by autothresholdr, detrendr, exampletestr, ijtiff, nandb.


See at CRAN