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 it's done better in these new ones). 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.
To install the release version (recommended) from CRAN, in R, enter
To install the development version, in R, first install
install.packages("devtools"). Then enter
First let's load the library:
I find it bizarre that base R has no
file.move. To move a file, you have to unintuitively rename it.
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:
#>  TRUE
Now let's put the file into the directory:
#> 1 file moved. 0 failed.
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.
"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"))
#>  TRUE TRUE
remove_filename_spaces(pattern = "txt$", replacement = "_")
#> 2 files renamed. 0 failed to rename.
list.files(pattern = "txt$")
#>  "file_1.txt" "file_2.txt"
file.remove(list.files(pattern = "txt$")) # clean up
#>  TRUE TRUE
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)
#>  1000
nth_number(pop, -1) # last number
#>  512
#> [] #>  1000 488 512
#> [] #>  "A population of " " comprised of " " dogs and " #>  " cats."
str_trim just trims whitespace. What if you want to trim something else? Now you can
#>  "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.
str_get_currencies()are gone. They are replaced by
str_nth_instance_indices()has been renamed to
str_last_instance_indices()have been renamed to
str_locate_last(). The aliases
locate_last()have been added.
str_elems()for extracting several single elements from a string.
str_, for example
str_before_last_dot()is a new alias for
str_extract_numbers()is a new alias for
nice_nums()now has the aliases
str_with_patterns()is defunct in light of
count_matches()is defunct in light of
strexwhich is reliable on mac.
strexv0.1.1; v0.1.0 didn't pass on mac on CRAN.
stringr-style string manipulation is now done by the
filesstringsnow depends upon. That was the main functionality of
filesstringsis going to be more dormant from now on.
nth_number_before_mth()and friends (there are 8 friends).
all_equal()and its documentation.
nth_number_after_mth()and friends (there are 8 friends).
file.move()with default value
FALSEto ensure that files are not accidentally overwritten.
remove_dirs()was claiming to have deleted directories that weren't there.
match_arg()for argument matching which is inspired by
RSAGA::match.arg.ext(). Its behaviour is almost identical but
RSAGAis a heavy package to depend upon so
filesstrings::match_arg()might be handy for package developers.
extract_numbers()which arose when integerish numbers outside the 32-bit integer range reared their heads.
all_equal()for dealing with arrays.
str_nth_instance_indices()are much faster.
paste_different_lengths()are gone. They didn't belong.
before_last_dot()now works in the case where the input has no dots, returning the input.
dir.delete()to conform with the
basenaming pattern of such functions.
PutFilesInDir()had is now default for
AllEqual()and improve its documentation.
ExtractNumerics()and its documentation.
StrReverse()is removed. Use
Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’by following Giorgio Spedicato's answer at http://stackoverflow.com/questions/42313373/r-cmd-check-note-found-no-calls-to-r-registerroutines-r-usedynamicsymbols