filesstrings v2.2.0


Monthly downloads



Handy File and String Manipulation

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



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. lifecycle JOSS
publication DOI


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


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



First let’s load the library:

#> Loading required package: stringr


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:

#> [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.

#> 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 required renaming and this was done successfully.
list.files(pattern = "txt$")
#> [1] "file_1.txt" "file_2.txt"
file.remove(list.files(pattern = "txt$"))  # clean up
#> [1] TRUE TRUE


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, n = 1)
#> [1] 1000
nth_number(pop, n = -1)  # last number
#> [1] 512

All the numbers in a string

#> [[1]]
#> [1] 1000  488  512

All the non-numbers in a string

#> [[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"


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.

Functions in filesstrings

Name Description
filesstrings-defunct Defunct functions
str_to_vec Convert a string to a vector of characters
singleize Remove back-to-back duplicates of a pattern in a string.
extract_numbers Extract numbers (or non-numbers) from a string.
give_ext Ensure a file name has the intended extension.
group_close Group together close adjacent elements of a vector.
str_after_nth Text before or after \(n\)th occurrence of pattern.
all_equal A more flexible version of all.equal for vectors.
before_last_dot Get the part of a string before the last period.
nice_nums Make string numbers comply with alphabetical order
put_in_pos Put specified strings in specified positions in an otherwise empty character vector.
currency Get the currencies of numbers within a string.
create_dir Create directories if they don't already exist
str_elem Extract a single character from a string, using its index.
str_nth_instance_indices Get the indices of the \(n\)th instance of a pattern.
str_with_patterns Which strings match the patterns?
trim_anything Trim something other than whitespace
locate_braces Locate the braces in a string.
match_arg Argument Matching
can_be_numeric Check if a string could be considered as numeric.
count_matches Count the number of the matches of a pattern in a string.
move_files Move files around.
str_split_by_nums Split a string by its numeric characters.
str_paste_elems Extract bits of a string and paste them together
unitize_dirs Put files with the same unit measurements into directories
nice_file_nums Make file numbers comply with alphabetical order
remove_quoted Remove the quoted parts of a string.
rename_with_nums Replace file names with numbers
filesstrings filesstrings: handy file and string manipulation
extend_char_vec Pad a character vector with empty strings.
remove_dir Remove directories
remove_filename_spaces Remove spaces in file names
str_split_camel_case Split a string based on CamelCase
No Results!

Vignettes of filesstrings

No Results!

Last month downloads


Type Package
License GPL-3
Encoding UTF-8
LazyData true
RoxygenNote 6.0.1
LinkingTo Rcpp, BH
SystemRequirements C++11
VignetteBuilder knitr
NeedsCompilation yes
Packaged 2018-04-18 11:01:48 UTC; rnolan
Repository CRAN
Date/Publication 2018-04-18 17:01:35 UTC

Include our badge in your README