├── .Rbuildignore ├── .gitattributes ├── .github ├── .gitignore └── workflows │ ├── R-CMD-check.yaml │ ├── pkgdown.yaml │ └── test-coverage.yaml ├── .gitignore ├── .pre-commit-config.yaml ├── CONDUCT.md ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── Paper ├── codemeta.json ├── paper.bib ├── paper.html └── paper.md ├── R ├── all-equal.R ├── arg-match.R ├── argument-checking.R ├── can-be-num.R ├── files.R ├── filesstrings-package.R ├── roxy.R ├── str-after.R ├── str-before.R ├── str-currency.R ├── str-elem.R ├── str-extract-non-nums.R ├── str-extract-nums.R ├── str-give-ext.R ├── str-locate.R ├── str-nice-nums.R ├── str-num-after.R ├── str-num-before.R ├── str-pad.R ├── str-put-in-pos.R ├── str-remove.R ├── str-singleize.R ├── str-split-by-nums.R ├── str-split.R ├── str-to-vec.R ├── str-trim.R └── utils.R ├── README.Rmd ├── README.md ├── codecov.yml ├── codemeta.json ├── cran-comments.md ├── filesstrings.Rproj ├── inst ├── CITATION └── WORDLIST ├── junk ├── Files.R ├── PossibleJunk.R ├── Strings.R ├── filesstrings.png ├── filesstrings.pptx ├── sticker.R └── sticker.png ├── man ├── all_equal.Rd ├── before_last_dot.Rd ├── can_be_numeric.Rd ├── create_dir.Rd ├── currency.Rd ├── extend_char_vec.Rd ├── extract_non_numerics.Rd ├── extract_numbers.Rd ├── figures │ └── logo.png ├── filesstrings.Rd ├── group_close.Rd ├── locate_braces.Rd ├── match_arg.Rd ├── move_files.Rd ├── nice_file_nums.Rd ├── nth_number_after_mth.Rd ├── nth_number_before_mth.Rd ├── put_in_pos.Rd ├── remove_dir.Rd ├── remove_filename_spaces.Rd ├── rename_with_nums.Rd ├── str_after_nth.Rd ├── str_before_nth.Rd ├── str_elem.Rd ├── str_elems.Rd ├── str_give_ext.Rd ├── str_locate_nth.Rd ├── str_nice_nums.Rd ├── str_paste_elems.Rd ├── str_remove_quoted.Rd ├── str_singleize.Rd ├── str_split_by_nums.Rd ├── str_split_camel_case.Rd ├── str_to_vec.Rd ├── str_trim_anything.Rd └── unitize_dirs.Rd ├── paper ├── codemeta.json ├── paper.bib ├── paper.html └── paper.md ├── tests ├── spelling.R ├── testthat.R └── testthat │ ├── test-files.R │ ├── test-roxy.R │ ├── test-strings.R │ └── test-utils.R └── vignettes └── files.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^CRAN-RELEASE$ 2 | ^.*\.Rproj$ 3 | ^\.Rproj\.user$ 4 | ^\.travis\.yml$ 5 | ^README\.Rmd$ 6 | ^README-.*\.png$ 7 | ^appveyor\.yml$ 8 | ^PossibleJunk$ 9 | ^codecov\.yml$ 10 | ^cran-comments\.md$ 11 | ^LICENSE$ 12 | ^revdep$ 13 | ^codemeta\.json$ 14 | ^paper$ 15 | ^CONDUCT\.md$ 16 | ^junk$ 17 | ^\.pre-commit-config\.yaml$ 18 | ^\.github$ 19 | ^CRAN-SUBMISSION$ 20 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.html linguist-documentation=true 2 | *.class linguist-documentation=true 3 | *.jar linguist-documentation=true 4 | *.java linguist-documentation=true 5 | *.cpp linguist-documentation=true 6 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macOS-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 24 | - {os: ubuntu-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'oldrel-1'} 26 | 27 | env: 28 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 29 | R_KEEP_PKG_SOURCE: yes 30 | 31 | steps: 32 | - uses: actions/checkout@v2 33 | 34 | - uses: r-lib/actions/setup-pandoc@v2 35 | 36 | - uses: r-lib/actions/setup-r@v2 37 | with: 38 | r-version: ${{ matrix.config.r }} 39 | http-user-agent: ${{ matrix.config.http-user-agent }} 40 | use-public-rspm: true 41 | 42 | - uses: r-lib/actions/setup-r-dependencies@v2 43 | with: 44 | extra-packages: any::rcmdcheck 45 | needs: check 46 | 47 | - uses: r-lib/actions/check-r-package@v2 48 | with: 49 | upload-snapshots: true 50 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | release: 9 | types: [published] 10 | workflow_dispatch: 11 | 12 | name: pkgdown 13 | 14 | jobs: 15 | pkgdown: 16 | runs-on: ubuntu-latest 17 | # Only restrict concurrency for non-PR jobs 18 | concurrency: 19 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 20 | env: 21 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 22 | steps: 23 | - uses: actions/checkout@v2 24 | 25 | - uses: r-lib/actions/setup-pandoc@v2 26 | 27 | - uses: r-lib/actions/setup-r@v2 28 | with: 29 | use-public-rspm: true 30 | 31 | - uses: r-lib/actions/setup-r-dependencies@v2 32 | with: 33 | extra-packages: any::pkgdown, local::. 34 | needs: website 35 | 36 | - name: Build site 37 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 38 | shell: Rscript {0} 39 | 40 | - name: Deploy to GitHub pages 🚀 41 | if: github.event_name != 'pull_request' 42 | uses: JamesIves/github-pages-deploy-action@4.1.4 43 | with: 44 | clean: false 45 | branch: gh-pages 46 | folder: docs 47 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: test-coverage 10 | 11 | jobs: 12 | test-coverage: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - uses: r-lib/actions/setup-r@v2 21 | with: 22 | use-public-rspm: true 23 | 24 | - uses: r-lib/actions/setup-r-dependencies@v2 25 | with: 26 | extra-packages: any::covr 27 | needs: coverage 28 | 29 | - name: Test coverage 30 | run: | 31 | covr::codecov( 32 | quiet = FALSE, 33 | clean = FALSE, 34 | install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") 35 | ) 36 | shell: Rscript {0} 37 | 38 | - name: Show testthat output 39 | if: always() 40 | run: | 41 | ## -------------------------------------------------------------------- 42 | find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true 43 | shell: bash 44 | 45 | - name: Upload test results 46 | if: failure() 47 | uses: actions/upload-artifact@v3 48 | with: 49 | name: coverage-test-failures 50 | path: ${{ runner.temp }}/package 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | .DS_Store 6 | inst/doc/ 7 | revdep/ 8 | CRAN-SUBMISSION 9 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # All available hooks: https://pre-commit.com/hooks.html 2 | # R specific hooks: https://github.com/lorenzwalthert/precommit 3 | repos: 4 | - repo: https://github.com/lorenzwalthert/precommit 5 | rev: v0.1.3 6 | hooks: 7 | - id: style-files 8 | args: [--style_pkg=styler, --style_fun=tidyverse_style] 9 | - id: roxygenize 10 | - id: codemeta-description-updated 11 | - id: use-tidy-description 12 | - id: readme-rmd-rendered 13 | - id: parsable-R 14 | - id: no-browser-statement 15 | - id: deps-in-desc 16 | - repo: https://github.com/pre-commit/pre-commit-hooks 17 | rev: v3.4.0 18 | hooks: 19 | - id: check-added-large-files 20 | args: ['--maxkb=200'] 21 | - id: end-of-file-fixer 22 | exclude: '\.Rd' 23 | - repo: local 24 | hooks: 25 | - id: forbid-to-commit 26 | name: Don't commit common R artifacts 27 | entry: Cannot commit .Rhistory, .RData, .Rds or .rds. 28 | language: fail 29 | files: '\.Rhistory|\.RData|\.Rds|\.rds$' 30 | # `exclude: ` to allow committing specific files. 31 | -------------------------------------------------------------------------------- /CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (http:contributor-covenant.org), version 1.0.0, available at 25 | http://contributor-covenant.org/version/1/0/0/. 26 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Type: Package 2 | Package: filesstrings 3 | Title: Handy File and String Manipulation 4 | Version: 3.4.0 5 | Authors@R: c( 6 | person("Rory", "Nolan", , "rorynoolan@gmail.com", role = c("aut", "cre", "cph"), 7 | comment = c(ORCID = "0000-0002-5239-4043")), 8 | person("Sergi", "Padilla-Parra", , "spadilla@well.ox.ac.uk", role = "ths", 9 | comment = c(ORCID = "0000-0002-8010-9481")) 10 | ) 11 | Maintainer: Rory Nolan 12 | Description: This started out as a package for file and string 13 | manipulation. Since then, the 'fs' and 'strex' packages emerged, 14 | offering functionality previously given by this package (but it's done 15 | better in these new ones). Those packages have hence almost pushed 16 | 'filesstrings' into extinction. However, it still has a small number 17 | of unique, handy file manipulation functions which can be seen in the 18 | vignette. One example is a function to remove spaces from all file 19 | names in a directory. 20 | License: GPL-3 21 | URL: https://rorynolan.github.io/filesstrings/, https://github.com/rorynolan/filesstrings 22 | BugReports: https://github.com/rorynolan/filesstrings/issues 23 | Depends: 24 | R (>= 3.5), 25 | stringr (>= 1.5) 26 | Imports: 27 | checkmate (>= 1.9.3), 28 | magrittr (>= 1.5), 29 | purrr (>= 0.3.0), 30 | rlang (>= 0.3.3), 31 | strex (>= 1.6), 32 | stringi (>= 1.7.8), 33 | withr (>= 2.1.0) 34 | Suggests: 35 | covr, 36 | dplyr, 37 | knitr, 38 | rmarkdown, 39 | spelling, 40 | testthat (>= 2.1) 41 | VignetteBuilder: 42 | knitr 43 | Encoding: UTF-8 44 | Language: en-US 45 | Roxygen: list(markdown = TRUE) 46 | RoxygenNote: 7.2.3 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(after_first) 4 | export(after_last) 5 | export(after_nth) 6 | export(all_equal) 7 | export(alphord_nums) 8 | export(before_first) 9 | export(before_last) 10 | export(before_last_dot) 11 | export(before_nth) 12 | export(can_be_numeric) 13 | export(create_dir) 14 | export(dir.remove) 15 | export(elem) 16 | export(elems) 17 | export(extend_char_vec) 18 | export(extract_currencies) 19 | export(extract_non_numerics) 20 | export(extract_numbers) 21 | export(file.move) 22 | export(first_currency) 23 | export(first_non_numeric) 24 | export(first_number) 25 | export(first_number_after_first) 26 | export(first_number_after_last) 27 | export(first_number_after_mth) 28 | export(first_number_before_first) 29 | export(first_number_before_last) 30 | export(first_number_before_mth) 31 | export(give_ext) 32 | export(group_close) 33 | export(last_currency) 34 | export(last_non_numeric) 35 | export(last_number) 36 | export(last_number_after_first) 37 | export(last_number_after_last) 38 | export(last_number_after_mth) 39 | export(last_number_before_first) 40 | export(last_number_before_last) 41 | export(last_number_before_mth) 42 | export(locate_braces) 43 | export(locate_first) 44 | export(locate_last) 45 | export(locate_nth) 46 | export(match_arg) 47 | export(move_files) 48 | export(nice_file_nums) 49 | export(nice_nums) 50 | export(nth_currency) 51 | export(nth_non_numeric) 52 | export(nth_number) 53 | export(nth_number_after_first) 54 | export(nth_number_after_last) 55 | export(nth_number_after_mth) 56 | export(nth_number_before_first) 57 | export(nth_number_before_last) 58 | export(nth_number_before_mth) 59 | export(paste_elems) 60 | export(put_in_pos) 61 | export(remove_dir) 62 | export(remove_filename_spaces) 63 | export(remove_quoted) 64 | export(rename_with_nums) 65 | export(singleize) 66 | export(split_by_numbers) 67 | export(split_by_nums) 68 | export(split_camel_case) 69 | export(str_after_first) 70 | export(str_after_last) 71 | export(str_after_nth) 72 | export(str_alphord_nums) 73 | export(str_before_first) 74 | export(str_before_last) 75 | export(str_before_last_dot) 76 | export(str_before_nth) 77 | export(str_can_be_numeric) 78 | export(str_elem) 79 | export(str_elems) 80 | export(str_extend_char_vec) 81 | export(str_extract_currencies) 82 | export(str_extract_non_numerics) 83 | export(str_extract_numbers) 84 | export(str_first_currency) 85 | export(str_first_non_numeric) 86 | export(str_first_number) 87 | export(str_first_number_after_first) 88 | export(str_first_number_after_last) 89 | export(str_first_number_after_mth) 90 | export(str_first_number_before_first) 91 | export(str_first_number_before_last) 92 | export(str_first_number_before_mth) 93 | export(str_give_ext) 94 | export(str_last_currency) 95 | export(str_last_non_numeric) 96 | export(str_last_number) 97 | export(str_last_number_after_first) 98 | export(str_last_number_after_last) 99 | export(str_last_number_after_mth) 100 | export(str_last_number_before_first) 101 | export(str_last_number_before_last) 102 | export(str_last_number_before_mth) 103 | export(str_locate_braces) 104 | export(str_locate_first) 105 | export(str_locate_last) 106 | export(str_locate_nth) 107 | export(str_match_arg) 108 | export(str_nice_nums) 109 | export(str_nth_currency) 110 | export(str_nth_non_numeric) 111 | export(str_nth_number) 112 | export(str_nth_number_after_first) 113 | export(str_nth_number_after_last) 114 | export(str_nth_number_after_mth) 115 | export(str_nth_number_before_first) 116 | export(str_nth_number_before_last) 117 | export(str_nth_number_before_mth) 118 | export(str_paste_elems) 119 | export(str_put_in_pos) 120 | export(str_remove_quoted) 121 | export(str_singleize) 122 | export(str_split_by_numbers) 123 | export(str_split_by_nums) 124 | export(str_split_camel_case) 125 | export(str_to_vec) 126 | export(str_trim_anything) 127 | export(to_vec) 128 | export(trim_anything) 129 | export(unitize_dirs) 130 | import(stringr) 131 | importFrom(magrittr,'%<>%') 132 | importFrom(magrittr,'%>%') 133 | importFrom(magrittr,'%T>%') 134 | importFrom(strex,match_arg) 135 | importFrom(stringi,'%stri$%') 136 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # `filesstrings` 3.4.0 2 | 3 | ## NEW FEATURES 4 | * Add github.io website to DESCRIPTION. 5 | 6 | 7 | # `filesstrings` 3.3.0 8 | 9 | ## NEW FEATURES 10 | * Code is now robust to changes to the `strex` package. 11 | 12 | 13 | # `filesstrings` 3.2.4 14 | 15 | ## BUG FIXES 16 | * Insist on bug-fixed `strex` v1.6.0. 17 | 18 | 19 | # `filesstrings` 3.2.3 20 | 21 | ## BUG FIXES 22 | * Insist on bug-fixed `stringi` v1.7.8 and `strex` v1.4.3. 23 | 24 | 25 | # `filesstrings` 3.2.2 26 | 27 | ## BUG FIXES 28 | * Remove `LazyData` from `DESCRIPTION` (was causing CRAN note). 29 | 30 | 31 | # `filesstrings` 3.2.1 32 | 33 | ## BUG FIXES 34 | * R version 3.5 or greater is needed for `strex` >= 1.4. 35 | 36 | 37 | # `filesstrings` 3.2.0 38 | 39 | ## BUG FIXES 40 | * Insist on `strex` >= 1.4 which has improved argument matching. 41 | 42 | 43 | # `filesstrings` 3.1.7 44 | 45 | ## BUG FIXES 46 | * Post `strex` v1.3.0 release adjustments. 47 | 48 | 49 | # `filesstrings` 3.1.6 50 | 51 | ## BUG FIXES 52 | * Ready the package not to break on next release of `strex` (v1.3.0). 53 | 54 | 55 | # `filesstrings` 3.1.5 56 | 57 | ## BUG FIXES 58 | * Fix `trim_anything()` docs. 59 | * Insist on latest `strex` (v1.1.1). 60 | 61 | 62 | # `filesstrings` 3.1.4 63 | 64 | ## BUG FIXES 65 | * Be ready not to break for `strex` v1.1.0. 66 | 67 | 68 | # `filesstrings` 3.1.3 69 | 70 | ## BUG FIXES 71 | * Demand bug-fixed `strex` v1.0.3. 72 | 73 | 74 | # `filesstrings` 3.1.2 75 | 76 | ## BUG FIXES 77 | * `all_equal()` was dealing inconsistently with attributes. 78 | 79 | 80 | # `filesstrings` 3.1.1 81 | 82 | ## BUG FIXES 83 | * Inherit bug fixes in `strex` v1.0.1. 84 | 85 | 86 | # `filesstrings` 3.1.0 87 | 88 | ## BREAKING CHANGES 89 | * `str_get_currency()` and `str_get_currencies()` are gone. They are replaced by `str_extract_currencies()` and `str_nth_currency()`, `str_first_currency()` and `str_last_currency()`. 90 | * `str_nth_instance_indices()` has been renamed to `str_locate_nth()` and `str_first_instance_indices()` and `str_last_instance_indices()` have been renamed to `str_locate_first()` and `str_locate_last()`. The aliases `locate_nth()`, `locate_first()` and `locate_last()` have been added. 91 | 92 | ## NEW FUNCTIONS 93 | * `str_elems()` for extracting several single elements from a string. 94 | 95 | ## NEW FUNCTION ALIASES 96 | * All string manipulation functions are now optionally prepended by `str_`, for example `str_before_last_dot()` is a new alias for `before_last_dot()` and `str_extract_numbers()` is a new alias for `extract_numbers()`. 97 | * `nice_nums()` now has the aliases `str_nice_nums()`, `str_alphord_nums()` and `alphord_nums()`. 98 | 99 | 100 | # `filesstrings` 3.0.1 101 | 102 | ## BUG FIXES 103 | * Depend on latest, least buggy `strex`. 104 | 105 | 106 | # `filesstrings` 3.0.0 107 | 108 | ## DEFUNCT 109 | * `str_with_patterns()` is defunct in light of `stringr::str_subset()`. 110 | * `count_matches()` is defunct in light of `stringr::str_count()`. 111 | 112 | ## BUG FIXES 113 | * Depend on a version of `strex` which is reliable on mac. 114 | 115 | 116 | # `filesstrings` 2.7.1 117 | 118 | ## BUG FIXES 119 | * Insist on `strex` v0.1.1; v0.1.0 didn't pass on mac on CRAN. 120 | 121 | 122 | # `filesstrings` 2.7.0 123 | 124 | ## NEW FEATURES 125 | * All of the `stringr`-style string manipulation is now done by the `strex` package, which `filesstrings` now depends upon. That was the main functionality of `filesstrings`, so `filesstrings` is going to be more dormant from now on. 126 | 127 | 128 | # `filesstrings` 2.6.0 129 | 130 | ## NEW FEATURES 131 | * Added functions `nth_number_before_mth()` and friends (there are 8 friends). 132 | 133 | ## MINOR IMPROVEMENTS 134 | * Improvements to documentation. 135 | 136 | 137 | # `filesstrings` 2.5.0 138 | 139 | ## NEW FEATURES 140 | * Improvement to `all_equal()` and its documentation. 141 | 142 | ## BUG FIXES 143 | * Fix to message of `file.move()`. 144 | 145 | 146 | # `filesstrings` 2.4.0 147 | 148 | ## NEW FEATURES 149 | * Added `nth_number_after_mth()` and friends (there are 8 friends). 150 | 151 | ## DEFUNCT 152 | * Defunct functions are now gone completely (as opposed to triggering a `.Defunct()` call). 153 | 154 | 155 | 156 | # `filesstrings` 2.3.0 157 | 158 | ## MINOR IMPROVEMENTS 159 | * Add an `overwrite` argument to `file.move()` with default value `FALSE` to ensure that files are not accidentally overwritten. 160 | 161 | 162 | # `filesstrings` 2.2.0 163 | 164 | ## MINOR IMPROVEMENTS 165 | * Speed up `extract_numbers()`. 166 | 167 | ## BUG FIXES 168 | * Fix some bad typing in C++ code. 169 | * `remove_dirs()` was claiming to have deleted directories that weren't there. 170 | 171 | 172 | # `filesstrings` 2.1.0 173 | 174 | ## NEW FEATURES 175 | * There is a new function `match_arg()` for argument matching which is inspired by `RSAGA::match.arg.ext()`. Its behaviour is almost identical but `RSAGA` is a heavy package to depend upon so `filesstrings::match_arg()` might be handy for package developers. 176 | 177 | 178 | # `filesstrings` 2.0.4 179 | 180 | ## BUG FIXES 181 | * Fix bug in `extract_numbers()` which arose when integerish numbers outside the 32-bit integer range reared their heads. 182 | 183 | 184 | # `filesstrings` 2.0.3 185 | 186 | ## BUG FIXES 187 | * Fix to message in `remove_filename_spaces()`. 188 | 189 | 190 | # `filesstrings` 2.0.2 191 | 192 | ## BUG FIXES 193 | * Fix to `all_equal()` for dealing with arrays. 194 | 195 | 196 | # `filesstrings` 2.0.1 197 | 198 | ## BUG FIXES 199 | * The new R doesn't like it when the working directory is changed by running examples. This required a fix which this patch provides. 200 | 201 | 202 | # `filesstrings` 2.0.0 203 | 204 | ## NEW FEATURES 205 | * Functions which were previously deprecated are now defunct. This brings the package completely in line with the tidyverse style. 206 | 207 | ## MINOR IMPROVEMENTS 208 | * `count_matches()` and `str_nth_instance_indices()` are much faster. 209 | * `merge_tables_on_disk()` and `paste_different_lengths()` are gone. They didn't belong. 210 | 211 | ## BUG FIXES 212 | * `before_last_dot()` now works in the case where the input has no dots, returning the input. 213 | 214 | 215 | # `filesstrings` 1.1.0 216 | 217 | ## NEW FEATURES 218 | * Added `first` and `last` companions for `nth` functions. 219 | 220 | ## MINOR IMPROVEMENTS 221 | * Minor documentation improvements. 222 | 223 | 224 | # `filesstrings` 1.1.0 225 | 226 | ## NEW FEATURES 227 | * Everything has been redone to conform with the tidyverse style guide. 228 | 229 | 230 | # `filesstrings` 1.0.0 231 | 232 | ## NEW FEATURES 233 | * 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")`. 234 | 235 | 236 | # `filesstrings` 0.4.2 237 | 238 | ## NEW FEATURES 239 | * The package now has the http://contributor-covenenant.org code of conduct. 240 | * The package now has the functions `file.move()` and `dir.delete()` to conform with the `base` naming pattern of such functions. 241 | 242 | ## DEFUNCT 243 | * `PutFilesInDir()` is gone. 244 | 245 | ## MINOR IMPROVEMENTS 246 | * The functionality that `PutFilesInDir()` had is now default for `MoveFiles()`. 247 | * The README and vignettes are improved. 248 | 249 | 250 | # `filesstrings` 0.4.1 251 | 252 | ## BUG FIXES 253 | * Minor fix to `AllEqual()`. 254 | 255 | 256 | # `filesstrings` 0.4.0 257 | 258 | ## BUG FIXES 259 | * Fix bug in `AllEqual()` and improve its documentation. 260 | * Improve `NA` handling of `ExtractNumerics()` and its documentation. 261 | 262 | ## MINOR IMPROVEMENTS 263 | * Improve README and vignette. 264 | 265 | 266 | # `filesstrings` 0.3.2 267 | 268 | ## BUG FIXES 269 | * A fix to make the package compatible with the new version of 'readr' courtesy of Jim Hester. 270 | 271 | ## MINOR IMPROVEMENTS 272 | * Minor documentation improvements. 273 | 274 | ## DEFUNCT 275 | * `StrReverse()` is removed. Use `stringi::stri_reverse()` instead. 276 | 277 | 278 | # `filesstrings` 0.3.1 279 | 280 | ## BUG FIXES 281 | * Fixed problem of 282 | `Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’` 283 | by following Giorgio Spedicato's answer at 284 | http://stackoverflow.com/questions/42313373/r-cmd-check-note-found-no-calls-to-r-registerroutines-r-usedynamicsymbols 285 | 286 | 287 | # `filesstrings` 0.3.0 288 | * The first edition that I think may be CRAN-worthy. 289 | -------------------------------------------------------------------------------- /Paper/codemeta.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": "https://raw.githubusercontent.com/codemeta/codemeta/master/codemeta.jsonld", 3 | "@type": "Code", 4 | "author": [ 5 | { 6 | "@id": "http://orcid.org/0000-0002-5239-4043", 7 | "@type": "Person", 8 | "email": "rorynoolan@gmail.com", 9 | "name": "Rory Nolan", 10 | "affiliation": "University of Oxford" 11 | }, 12 | { 13 | "@id": "http://0000-0002-8010-9481", 14 | "@type": "Person", 15 | "email": "spadilla@well.ox.ac.uk", 16 | "name": "Sergi Padilla", 17 | "affiliation": "University of Oxford" 18 | } 19 | ], 20 | "identifier": "", 21 | "codeRepository": "https://github.com/rorynolan/filesstrings", 22 | "datePublished": "2017-04-11", 23 | "dateModified": "2017-04-11", 24 | "dateCreated": "2017-04-11", 25 | "description": "An R package for file and string manipulation", 26 | "keywords": "R, file, string", 27 | "license": "GPL v3.0", 28 | "title": "filesstrings", 29 | "version": "0.3.2" 30 | } 31 | -------------------------------------------------------------------------------- /Paper/paper.bib: -------------------------------------------------------------------------------- 1 | @Manual{R, 2 | title = {R: A Language and Environment for Statistical Computing}, 3 | author = {{R Core Team}}, 4 | organization = {R Foundation for Statistical Computing}, 5 | address = {Vienna, Austria}, 6 | year = {2017}, 7 | url = {https://www.R-project.org/}, 8 | } 9 | @Manual{RStudio, 10 | title = {RStudio: Integrated Development Environment for R}, 11 | author = {{RStudio Team}}, 12 | organization = {RStudio, Inc.}, 13 | address = {Boston, MA}, 14 | year = {2016}, 15 | url = {http://www.rstudio.com/}, 16 | } 17 | @Manual{readr, 18 | title = {readr: Read Rectangular Text Data}, 19 | author = {Hadley Wickham and Jim Hester and Romain Francois}, 20 | year = {2017}, 21 | note = {R package version 1.1.0}, 22 | url = {https://CRAN.R-project.org/package=readr}, 23 | } 24 | @Manual{tibble, 25 | title = {tibble: Simple Data Frames}, 26 | author = {Hadley Wickham and Romain Francois and Kirill Müller}, 27 | year = {2017}, 28 | note = {R package version 1.3.0}, 29 | url = {https://CRAN.R-project.org/package=tibble}, 30 | } 31 | @article{Rcpp, 32 | author = {Dirk Eddelbuettel and Romain Francois}, 33 | title = {Rcpp: Seamless R and C++ Integration}, 34 | journal = {Journal of Statistical Software}, 35 | volume = {40}, 36 | number = {1}, 37 | year = {2011}, 38 | keywords = {}, 39 | abstract = {The Rcpp package simplifies integrating C++ code with R. It provides a consistent C++ class hierarchy that maps various types of R objects (vectors, matrices, functions, environments, . . . ) to dedicated C++ classes. Object interchange between R and C++ is managed by simple, flexible and extensible concepts which include broad support for C++ Standard Template Library idioms. C++ code can both be compiled, linked and loaded on the fly, or added via packages. Flexible error and exception code handling is provided. Rcpp substantially lowers the barrier for programmers wanting to combine C++ code with R.}, 40 | issn = {1548-7660}, 41 | pages = {1--18}, 42 | doi = {10.18637/jss.v040.i08}, 43 | url = {https://www.jstatsoft.org/index.php/jss/article/view/v040i08} 44 | } 45 | @Manual{magrittr, 46 | title = {magrittr: A Forward-Pipe Operator for R}, 47 | author = {Stefan Milton Bache and Hadley Wickham}, 48 | year = {2014}, 49 | note = {R package version 1.5}, 50 | url = {https://CRAN.R-project.org/package=magrittr}, 51 | } 52 | @Manual{ore, 53 | title = {ore: An R Interface to the Oniguruma Regular Expression Library}, 54 | author = {Jon Clayden and based on Onigmo by K. Kosako and K. Takata}, 55 | year = {2016}, 56 | note = {R package version 1.5.0}, 57 | url = {https://CRAN.R-project.org/package=ore}, 58 | } 59 | @Manual{dplyr, 60 | title = {dplyr: A Grammar of Data Manipulation}, 61 | author = {Hadley Wickham and Romain Francois}, 62 | year = {2016}, 63 | note = {R package version 0.5.0}, 64 | url = {https://CRAN.R-project.org/package=dplyr}, 65 | } 66 | @Manual{matrixStats, 67 | title = {matrixStats: Functions that Apply to Rows and Columns of Matrices (and to Vectors)}, 68 | author = {Henrik Bengtsson}, 69 | year = {2017}, 70 | note = {R package version 0.52.1}, 71 | url = {https://CRAN.R-project.org/package=matrixStats}, 72 | } 73 | @Manual{stringr, 74 | title = {stringr: Simple, Consistent Wrappers for Common String Operations}, 75 | author = {Hadley Wickham}, 76 | year = {2017}, 77 | note = {R package version 1.2.0}, 78 | url = {https://CRAN.R-project.org/package=stringr}, 79 | } 80 | @Manual{stringi, 81 | title = {R package stringi: Character string processing facilities}, 82 | author = {Marek Gagolewski and Bartek Tartanus}, 83 | year = {2016}, 84 | url = {http://www.gagolewski.com/software/stringi/}, 85 | } 86 | -------------------------------------------------------------------------------- /Paper/paper.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'filesstrings: An R package for file and string manipulation' 3 | tags: 4 | - R 5 | - file 6 | - string 7 | authors: 8 | - name: Rory Nolan 9 | orcid: 0000-0002-5239-4043 10 | affiliation: 1 11 | - name: Sergi Padilla-Parra 12 | orcid: 0000-0002-8010-9481 13 | affiliation: 1, 2 14 | affiliations: 15 | - name: Wellcome Trust Centre for Human Genetics, University of Oxford 16 | index: 1 17 | - name: Department of Structural Biology, University of Oxford 18 | index: 2 19 | date: 11 April 2017 20 | bibliography: paper.bib 21 | nocite: | 22 | @R, @RStudio, @readr, @tibble, @Rcpp, @magrittr, @ore, @dplyr, @matrixStats, @stringr, @stringi 23 | --- 24 | 25 | # Summary 26 | `filesstrings` is an R package providing convenient functions for moving files, deleting directories, and a variety of string operations that facilitate manipulating file names and extracting information from strings. For example, R has no `file.move()`, just `file.copy()` and `file.rename()`, so the best way to move a file was to unintuitively rename it. `filesstrings` provides `file.move()`. The package's string operations mostly pertain to dealing with numbers contained within strings. It has a function `NiceFileNums()` for fixing file names such that their numbering is consistent with alphabetical order. For example, 'file10.txt' comes before 'file9.txt' in alphabetical order, so `NiceFileNums()` recognises this and renames them to 'file10.txt' and 'file09.txt' respectively. See documentation at https://cran.r-project.org/package=filesstrings. 27 | 28 | # References 29 | -------------------------------------------------------------------------------- /R/all-equal.R: -------------------------------------------------------------------------------- 1 | #' An alternative version of [base::all.equal()]. 2 | #' 3 | #' @description 4 | #' This function will return `TRUE` whenever [base::all.equal()] 5 | #' would return `TRUE`, however it will also return `TRUE` in some other cases: 6 | #' * If `a` is given and `b` is not, `TRUE` will be returned if all of the 7 | #' elements of `a` are the same. 8 | #' * If `a` is a scalar and `b` is a vector or array, `TRUE` will be returned 9 | #' if every element in `b` is equal to `a`. 10 | #' * If `a` is a vector or array and `b` is a scalar, `TRUE` will be returned 11 | #' if every element in `a` is equal to `b`. 12 | #' 13 | #' This function ignores names and attributes (except for `dim`). 14 | #' 15 | #' When this function does not return `TRUE`, it returns `FALSE` (unless it 16 | #' errors). This is unlike [base::all.equal()]. 17 | #' 18 | #' @note \itemize{\item This behaviour is totally different from 19 | #' [base::all.equal()]. \item There's also [dplyr::all_equal()], which is 20 | #' different again. To avoid confusion, always use the full 21 | #' `filesstrings::all_equal()` and never `library(filesstrings)` followed by 22 | #' just `all_equal()`.} 23 | #' 24 | #' @param a A vector, array or list. 25 | #' @param b Either `NULL` or a vector, array or list of length either 1 or 26 | #' `length(a)`. 27 | #' @return `TRUE` if "equality of all" is satisfied (as detailed in 28 | #' 'Description' above) and `FALSE` otherwise. 29 | #' @examples 30 | #' all_equal(1, rep(1, 3)) 31 | #' all_equal(2, 1:3) 32 | #' all_equal(1:4, 1:4) 33 | #' all_equal(1:4, c(1, 2, 3, 3)) 34 | #' all_equal(rep(1, 10)) 35 | #' all_equal(c(1, 88)) 36 | #' all_equal(1:2) 37 | #' all_equal(list(1:2)) 38 | #' all_equal(1:4, matrix(1:4, nrow = 2)) # note that this gives TRUE 39 | #' @export 40 | all_equal <- function(a, b = NULL) { 41 | checkmate::assert( 42 | checkmate::check_null(a), 43 | checkmate::check_vector(a), 44 | checkmate::check_list(a), 45 | checkmate::check_array(a) 46 | ) 47 | checkmate::assert( 48 | checkmate::check_null(b), 49 | checkmate::check_vector(b), 50 | checkmate::check_list(b), 51 | checkmate::check_array(b) 52 | ) 53 | if (is.null(b)) { 54 | return(alleq1(a)) 55 | } 56 | if (is.array(a) || is.array(b)) { 57 | return(alleq_arr(a, b)) 58 | } 59 | if (is.null(a) && (!is.null(b))) { 60 | return(FALSE) 61 | } 62 | if (xor(length(a) == 0, length(b) == 0)) { 63 | return(FALSE) 64 | } 65 | if (length(a) == 1) { 66 | a <- rep(a, length(b)) 67 | } 68 | if (length(b) == 1) { 69 | b <- rep(b, length(a)) 70 | } 71 | return(isTRUE(all.equal(a, b, check.names = FALSE, check.attributes = FALSE))) 72 | } 73 | 74 | alleq1 <- function(x) { 75 | if (rlang::is_atomic(x)) { 76 | return(isTRUE(all(x == x[[1]])) || all(is.na(x))) 77 | } 78 | if (is.list(x)) { 79 | x %<>% lapply(function(y) { 80 | y %T>% { 81 | mostattributes(.) <- NULL 82 | } 83 | }) 84 | } 85 | return(length(unique(x)) == 1) 86 | } 87 | 88 | alleq_arr <- function(a, b) { 89 | checkmate::assert(checkmate::check_array(a), checkmate::check_array(b)) 90 | if (is.array(a) && isTRUE(checkmate::check_scalar(b))) { 91 | b %<>% array(dim = dim(a)) 92 | } 93 | if (is.array(b) && isTRUE(checkmate::check_scalar(a))) { 94 | a %<>% array(dim = dim(b)) 95 | } 96 | if (is.array(a)) { 97 | if (!is.array(b)) { 98 | return(FALSE) 99 | } 100 | if (!all_equal(dim(a), dim(b))) { 101 | return(FALSE) 102 | } 103 | a %<>% as.vector() 104 | b %<>% as.vector() 105 | } 106 | if (is.array(b)) { 107 | if (!is.array(a)) { 108 | return(FALSE) 109 | } 110 | } 111 | isTRUE(all.equal(a, b, check.names = FALSE, check.attributes = FALSE)) 112 | } 113 | -------------------------------------------------------------------------------- /R/arg-match.R: -------------------------------------------------------------------------------- 1 | #' Argument Matching 2 | #' 3 | #' Copy of [strex::match_arg()]. 4 | #' 5 | #' @param ... Pass-through to `strex` function. 6 | #' 7 | #' @export 8 | match_arg <- function(...) { 9 | strex::match_arg(...) 10 | } 11 | 12 | #' @rdname match_arg 13 | #' @export 14 | str_match_arg <- match_arg 15 | -------------------------------------------------------------------------------- /R/argument-checking.R: -------------------------------------------------------------------------------- 1 | argchk_move_files <- function(files, destinations, overwrite) { 2 | checkmate::assert_character(files) 3 | checkmate::assert_character(destinations) 4 | checkmate::assert_flag(overwrite) 5 | checkmate::assert_file_exists(files) 6 | checkmate::assert_character(destinations, min.chars = 1) 7 | anydup_files <- anyDuplicated(files) 8 | if (anydup_files) { 9 | stop( 10 | "`files` must not have any duplicated elements.", "\n", 11 | " * Element ", anydup_files, " of `files` is a duplicate." 12 | ) 13 | } 14 | if (length(destinations) == 1) destinations %<>% rep(length(files)) 15 | if (length(destinations) != length(files)) { 16 | stop( 17 | "The number of destinations must be equal to 1 or equal to the ", 18 | "number of files to be moved." 19 | ) 20 | } 21 | list(files = files, destinations = destinations, overwrite = overwrite) 22 | } 23 | -------------------------------------------------------------------------------- /R/can-be-num.R: -------------------------------------------------------------------------------- 1 | #' Check if a string could be considered as numeric. 2 | #' 3 | #' Copy of [strex::str_can_be_numeric()]. 4 | #' 5 | #' @inheritParams match_arg 6 | #' 7 | #' @export 8 | can_be_numeric <- function(...) { 9 | strex::str_can_be_numeric(...) 10 | } 11 | 12 | #' @rdname can_be_numeric 13 | #' @export 14 | str_can_be_numeric <- can_be_numeric 15 | -------------------------------------------------------------------------------- /R/files.R: -------------------------------------------------------------------------------- 1 | #' Create directories if they don't already exist 2 | #' 3 | #' Given the names of (potential) directories, create the ones that do not 4 | #' already exist. 5 | #' @param ... The names of the directories, specified via relative or absolute 6 | #' paths. Duplicates are ignored. 7 | #' @return Invisibly, a vector with a `TRUE` for each time a directory was 8 | #' actually created and a `FALSE` otherwise. This vector is named with the 9 | #' paths of the directories that were passed to the function. 10 | #' @examples 11 | #' \dontrun{ 12 | #' create_dir(c("mydir", "yourdir")) 13 | #' remove_dir(c("mydir", "yourdir")) 14 | #' } 15 | #' @export 16 | create_dir <- function(...) { 17 | dirs <- unique(unlist(...)) 18 | created <- vapply(dirs, function(dir) { 19 | if (!dir.exists(dir)) { 20 | dir.create(dir) 21 | TRUE 22 | } else { 23 | FALSE 24 | } 25 | }, logical(1)) 26 | names(created) <- dirs 27 | msg <- sum(created) %>% { 28 | ifelse(., paste( 29 | ., ifelse(. == 1, "directory", "directories"), 30 | "created. " 31 | ), 32 | "" 33 | ) 34 | } 35 | n_not_created <- sum(!created) 36 | if (n_not_created) { 37 | msg %<>% paste0( 38 | n_not_created, 39 | ifelse(n_not_created == 1, " directory", " directories"), 40 | " not created because ", 41 | ifelse(n_not_created == 1, 42 | "it already exists.", 43 | "they already exist." 44 | ) 45 | ) 46 | } 47 | message(msg) 48 | invisible(created) 49 | } 50 | 51 | #' Remove directories 52 | #' 53 | #' Delete directories and all of their contents. 54 | #' @param ... The names of the directories, specified via relative or absolute 55 | #' paths. 56 | #' @return Invisibly, a logical vector with `TRUE` for each success and 57 | #' `FALSE` for failures. 58 | #' @examples 59 | #' \dontrun{ 60 | #' sapply(c("mydir1", "mydir2"), dir.create) 61 | #' remove_dir(c("mydir1", "mydir2")) 62 | #' } 63 | #' @export 64 | remove_dir <- function(...) { 65 | dirs <- unlist(list(...)) 66 | exist <- dir.exists(dirs) 67 | outcome <- !as.logical(vapply(dirs, unlink, integer(1), recursive = TRUE)) 68 | outcome[!exist] <- FALSE 69 | outcome %>% 70 | { 71 | paste( 72 | sum(.), ifelse(sum(.) == 1, "directory", "directories"), 73 | "deleted.", sum(!.), "failed to delete." 74 | ) 75 | } %>% 76 | message() 77 | invisible(outcome) 78 | } 79 | 80 | #' @rdname remove_dir 81 | #' @export 82 | dir.remove <- remove_dir 83 | 84 | #' Get the new path of a file that is to be moved. 85 | #' 86 | #' `move_files()` actually moves files, but it uses this function to get the 87 | #' full path of the file's new home. 88 | #' 89 | #' @param file The file to move. 90 | #' @param destination Folder to move the file to. 91 | #' 92 | #' @return A string. The file's new home. 93 | #' 94 | #' @examples 95 | #' get_new_home("a", "b") 96 | #' @noRd 97 | get_new_home <- function(file, destination) { 98 | # This function does not move any files, it helps `move_files()` which does 99 | file %<>% normalizePath() 100 | file_name_base <- basename(file) 101 | destination %<>% { 102 | suppressWarnings(normalizePath(.)) 103 | } # replace tildes 104 | paste0(destination, "/", file_name_base) 105 | } 106 | 107 | #' Move files around. 108 | #' 109 | #' Move specified files into specified directories 110 | #' 111 | #' If there are \eqn{n} files, there must be either \eqn{1} or \eqn{n} 112 | #' directories. If there is one directory, then all \eqn{n} files are moved 113 | #' there. If there are \eqn{n} directories, then each file is put into its 114 | #' respective directory. This function also works to move directories. 115 | #' 116 | #' If you try to move files to a directory that doesn't exist, the directory is 117 | #' first created and then the files are put inside. 118 | #' 119 | #' @param files A character vector of files to move (relative or absolute 120 | #' paths). 121 | #' @param destinations A character vector of the destination directories into 122 | #' which to move the files. 123 | #' @param overwrite Allow overwriting of files? Default no. 124 | #' @return Invisibly, a logical vector with a `TRUE` for each time the operation 125 | #' succeeded and a `FALSE` for every fail. 126 | #' @examples 127 | #' \dontrun{ 128 | #' dir.create("dir") 129 | #' files <- c("1litres_1.txt", "1litres_30.txt", "3litres_5.txt") 130 | #' file.create(files) 131 | #' file.move(files, "dir") 132 | #' } 133 | #' @export 134 | move_files <- function(files, destinations, overwrite = FALSE) { 135 | if (is_l0_char(files)) { 136 | message("0 files moved. 0 failed.") 137 | return(invisible(logical(0))) 138 | } 139 | destinations <- argchk_move_files( 140 | files = files, 141 | destinations = destinations, 142 | overwrite = overwrite 143 | )$destinations 144 | n_created_dirs <- sum(suppressMessages(create_dir(destinations))) 145 | if (n_created_dirs > 0) { 146 | message( 147 | n_created_dirs, " ", "director", 148 | ifelse(n_created_dirs == 1, "y", "ies"), 149 | " created." 150 | ) 151 | } 152 | new_paths <- get_new_home(files, destinations) 153 | overwrite_attempt <- any(file.exists(new_paths)) 154 | out <- purrr::map2_lgl( 155 | files, new_paths, 156 | ~ move_file_basic(.x, .y, overwrite) 157 | ) 158 | n_succeeded <- sum(out) 159 | n_failed <- sum(!out) 160 | message( 161 | n_succeeded, ifelse(n_succeeded == 1, " file", " files"), 162 | " moved. ", n_failed, " failed." 163 | ) 164 | if (sum(!out) && !overwrite && overwrite_attempt) { 165 | message( 166 | "Some files failed to move because it would have caused files ", 167 | "to be overwritten. ", "\n", 168 | " * To allow overwriting, use `overwrite = TRUE`." 169 | ) 170 | } 171 | invisible(out) 172 | } 173 | 174 | #' @rdname move_files 175 | #' @export 176 | file.move <- move_files 177 | 178 | move_file_basic <- function(file, new_path, overwrite) { 179 | out <- FALSE 180 | if (file.exists(new_path)) { 181 | if (overwrite) { 182 | file.rename(file, new_path) 183 | if (!file.exists(file) && file.exists(new_path)) { 184 | out <- TRUE 185 | } 186 | } 187 | } else { 188 | file.rename(file, new_path) 189 | if (!file.exists(file) && file.exists(new_path)) { 190 | out <- TRUE 191 | } 192 | } 193 | out 194 | } 195 | 196 | #' Make file numbers comply with alphabetical order 197 | #' 198 | #' If files are numbered, their numbers may not *comply* with alphabetical 199 | #' order, i.e. "file2.ext" comes after "file10.ext" in alphabetical order. This 200 | #' function renames the files in the specified directory such that they comply 201 | #' with alphabetical order, so here "file2.ext" would be renamed to 202 | #' "file02.ext". 203 | #' 204 | #' It works on file names with more than one number in them e.g. 205 | #' "file01part3.ext" (a file with 2 numbers). All the file names that it works 206 | #' on must have the same number of numbers, and the non-number bits must be the 207 | #' same. One can limit the renaming to files matching a certain pattern. This 208 | #' function wraps [nice_nums()], which does the string operations, but 209 | #' not the renaming. To see examples of how this function works, see the 210 | #' examples in that function's documentation. 211 | #' 212 | #' @param dir Path (relative or absolute) to the directory in which to do the 213 | #' renaming (default is current working directory). 214 | #' @param pattern A regular expression. If specified, files to be renamed are 215 | #' restricted to ones matching this pattern (in their name). 216 | #' @return A logical vector with a `TRUE` for each successful rename 217 | #' (should be all `TRUE`s) and a `FALSE` otherwise. 218 | #' 219 | #' @examples 220 | #' \dontrun{ 221 | #' dir.create("NiceFileNums_test") 222 | #' setwd("NiceFileNums_test") 223 | #' files <- c("1litres_1.txt", "1litres_30.txt", "3litres_5.txt") 224 | #' file.create(files) 225 | #' nice_file_nums() 226 | #' nice_file_nums(pattern = "\\.txt$") 227 | #' setwd("..") 228 | #' dir.remove("NiceFileNums_test") 229 | #' } 230 | #' @export 231 | nice_file_nums <- function(dir = ".", pattern = NA) { 232 | checkmate::assert_directory_exists(dir) 233 | withr::local_dir(dir) 234 | if (is.na(pattern)) { 235 | lf <- list.files() 236 | } else { 237 | lf <- list.files(pattern = pattern) 238 | } 239 | renamed <- file.rename(lf, nice_nums(lf)) 240 | message( 241 | sum(renamed), " files renamed into the desired format. ", 242 | sum(!renamed), " failed." 243 | ) 244 | invisible(renamed) 245 | } 246 | 247 | #' Remove spaces in file names 248 | #' 249 | #' Remove spaces in file names in a specified directory, replacing them with 250 | #' whatever you want, default nothing. 251 | #' 252 | #' @param dir The directory in which to perform the operation. 253 | #' @param pattern A regular expression. If specified, only files matching this 254 | #' pattern will be treated. 255 | #' @param replacement What do you want to replace the spaces with? This 256 | #' defaults to nothing, another sensible choice would be an underscore. 257 | #' @return A logical vector indicating which operation succeeded for each of the 258 | #' files attempted. Using a missing value for a file or path name will always 259 | #' be regarded as a failure. 260 | #' @examples 261 | #' \dontrun{ 262 | #' dir.create("RemoveFileNameSpaces_test") 263 | #' setwd("RemoveFileNameSpaces_test") 264 | #' files <- c("1litres 1.txt", "1litres 30.txt", "3litres 5.txt") 265 | #' file.create(files) 266 | #' remove_filename_spaces() 267 | #' list.files() 268 | #' setwd("..") 269 | #' dir.remove("RemoveFileNameSpaces_test") 270 | #' } 271 | #' @export 272 | remove_filename_spaces <- function(dir = ".", pattern = "", replacement = "") { 273 | checkmate::assert_directory_exists(dir) 274 | withr::local_dir(dir) 275 | lf <- list.files(pattern = pattern) 276 | new_names <- str_replace_all(lf, " ", replacement) 277 | new_new_names <- new_names[new_names != lf] 278 | if (any(new_new_names %in% lf)) { 279 | index <- which.max(lf == new_new_names[1] & str_detect(lf, " ")) 280 | spacey <- lf[index] 281 | spaceless <- new_new_names[1] 282 | stop( 283 | "Not renaming because to do so would also overwrite.", "\n", 284 | " * For example, both '", spacey, "' and '", spaceless, 285 | "' already exist, so to rename '", spacey, "' to '", spaceless, 286 | "' would be to overwrite '", spaceless, "'." 287 | ) 288 | } 289 | n_to_rename <- length(setdiff(lf, new_names)) 290 | outcome <- logical() 291 | if (n_to_rename) { 292 | outcome <- file.rename(lf, new_names) 293 | message( 294 | n_to_rename, " file", ifelse(n_to_rename == 1, "", "s"), 295 | " required renaming and this was done successfully." 296 | ) 297 | } else { 298 | message("No files required renaming.") 299 | } 300 | invisible(outcome) 301 | } 302 | 303 | #' Replace file names with numbers 304 | #' 305 | #' Rename the files in the directory, replacing file names with numbers only. 306 | #' 307 | #' @param dir The directory in which to rename the files (relative or absolute 308 | #' path). Defaults to current working directory. 309 | #' @param pattern A regular expression. If specified, only files with names 310 | #' matching this pattern will be treated. 311 | #' @return A logical vector with a `TRUE` for each successful renaming and a 312 | #' `FALSE` otherwise. 313 | #' @examples 314 | #' \dontrun{ 315 | #' dir.create("RenameWithNums_test") 316 | #' setwd("RenameWithNums_test") 317 | #' files <- c("1litres 1.txt", "1litres 30.txt", "3litres 5.txt") 318 | #' file.create(files) 319 | #' rename_with_nums() 320 | #' list.files() 321 | #' setwd("..") 322 | #' dir.remove("RenameWithNums_test") 323 | #' } 324 | #' @export 325 | rename_with_nums <- function(dir = ".", pattern = NULL) { 326 | checkmate::assert_directory_exists(dir) 327 | withr::local_dir(dir) 328 | lf <- list.files(pattern = pattern) 329 | l <- length(lf) 330 | if (l == 0) stop("No files found to rename.") 331 | ext <- unique(tools::file_ext(lf)) 332 | if (length(ext) != 1) { 333 | stop( 334 | "Files matching pattern have different extensions.", "\n", " * ", 335 | " This function only works with files of the same file extension." 336 | ) 337 | } 338 | new_names <- nice_nums(paste0(seq_len(l), ".", ext)) 339 | if (any(new_names %in% lf)) { 340 | stop( 341 | "Some of the names are already in the desired format, for example '", 342 | new_names[new_names %in% lf][1], "'.", "\n", 343 | " * Unable to proceed as renaming may result in deletion." 344 | ) 345 | } 346 | file.rename(lf, new_names) 347 | } 348 | 349 | #' Put files with the same unit measurements into directories 350 | #' 351 | #' Say you have a number of files with "5min" in their names, number with 352 | #' "10min" in the names, a number with "15min" in their names and so on, and 353 | #' you'd like to put them into directories named "5min", "10min", "15min" and so 354 | #' on. This function does this, but not just for the unit "min", for any unit. 355 | #' 356 | #' This function takes the number to be the last number (as defined in 357 | #' [nth_number()]) before the first occurrence of the unit name. There is the 358 | #' option to only treat files matching a certain pattern. 359 | #' 360 | #' @param unit The unit upon which to base the categorizing. 361 | #' @param pattern If set, only files with names matching this pattern will be 362 | #' treated. 363 | #' @param dir In which directory do you want to perform this action (defaults to 364 | #' current)? 365 | #' @return Invisibly `TRUE` if the operation is successful, if not there will be 366 | #' an error. 367 | #' @examples 368 | #' \dontrun{ 369 | #' dir.create("UnitDirs_test") 370 | #' setwd("UnitDirs_test") 371 | #' files <- c("1litres_1.txt", "1litres_3.txt", "3litres.txt", "5litres_1.txt") 372 | #' file.create(files) 373 | #' unitize_dirs("litres", "\\.txt") 374 | #' setwd("..") 375 | #' dir.remove("UnitDirs_test") 376 | #' } 377 | #' @export 378 | unitize_dirs <- function(unit, pattern = NULL, dir = ".") { 379 | checkmate::assert_directory_exists(dir) 380 | withr::local_dir(dir) 381 | lf <- list.files(pattern = pattern) 382 | if (!all(str_detect(lf, unit))) { 383 | stop(paste0("The file names must all contain the word '", unit, "'.")) 384 | } 385 | up_to_first_units <- str_before_first(lf, unit) 386 | nums <- vapply(up_to_first_units, last_number, numeric(1), decimals = TRUE) 387 | un <- unique(nums) 388 | for (i in un) { 389 | files <- lf[nums == i] 390 | move_files(files, paste0(i, unit)) 391 | } 392 | invisible(TRUE) 393 | } 394 | -------------------------------------------------------------------------------- /R/filesstrings-package.R: -------------------------------------------------------------------------------- 1 | #' @import stringr 2 | #' @importFrom magrittr '%>%' '%<>%' '%T>%' 3 | #' @importFrom strex match_arg 4 | #' @importFrom stringi '%stri$%' 5 | NULL 6 | 7 | ## quiets concerns of R CMD check re: the .'s that appear in pipelines 8 | if (getRversion() >= "2.15.1") { 9 | utils::globalVariables(c(".")) 10 | } 11 | 12 | #' `filesstrings`: handy file and string manipulation 13 | #' 14 | #' This started out as a package for file and string manipulation. Since then, 15 | #' the `fs` file manipulation package and the `strex` string manipulation 16 | #' package emerged, offering functionality previously given by this package (but 17 | #' slightly better). Those packages have hence almost pushed 'filesstrings' into 18 | #' extinction. However, it still has a small number of unique, handy file 19 | #' manipulation functions which can be seen in the `r roxy_files_vignette()`. 20 | #' One example is a function to remove spaces from all file names in a 21 | #' directory. 22 | #' 23 | #' @docType package 24 | #' @name filesstrings 25 | #' @aliases filesstrings-package 26 | #' @references Rory Nolan and Sergi Padilla-Parra (2017). filesstrings: An R 27 | #' package for file and string manipulation. The Journal of Open Source 28 | #' Software, 2(14). \doi{10.21105/joss.00260}. 29 | NULL 30 | -------------------------------------------------------------------------------- /R/roxy.R: -------------------------------------------------------------------------------- 1 | roxy_files_vignette <- function() { 2 | paste0( 3 | "[vignette]", 4 | "(https://cran.r-project.org/package=filesstrings/vignettes/files.html)." 5 | ) 6 | } 7 | -------------------------------------------------------------------------------- /R/str-after.R: -------------------------------------------------------------------------------- 1 | #' Text after the `n`th occurrence of pattern. 2 | #' 3 | #' Copies of [strex::str_after_nth()] and friends. 4 | #' 5 | #' @inheritParams match_arg 6 | #' @export 7 | str_after_nth <- function(...){ 8 | strex::str_after_nth(...) 9 | } 10 | 11 | #' @rdname str_after_nth 12 | #' @export 13 | after_nth <- function(...){ 14 | strex::str_after_nth(...) 15 | } 16 | 17 | #' @rdname str_after_nth 18 | #' @export 19 | str_after_first <- function(...){ 20 | strex::str_after_first(...) 21 | } 22 | 23 | #' @rdname str_after_nth 24 | #' @export 25 | after_first <- function(...){ 26 | strex::str_after_first(...) 27 | } 28 | 29 | #' @rdname str_after_nth 30 | #' @export 31 | str_after_last <- function(...){ 32 | strex::str_after_last(...) 33 | } 34 | 35 | #' @rdname str_after_nth 36 | #' @export 37 | after_last <- function(...){ 38 | strex::str_after_last(...) 39 | } 40 | -------------------------------------------------------------------------------- /R/str-before.R: -------------------------------------------------------------------------------- 1 | #' Text before the `n`th occurrence of pattern. 2 | #' 3 | #' Copies of [strex::str_before_nth()] and friends. 4 | #' 5 | #' @inheritParams match_arg 6 | #' @export 7 | str_before_nth <- function(...){ 8 | strex::str_before_nth(...) 9 | } 10 | 11 | #' @rdname str_before_nth 12 | #' @export 13 | before_nth <- function(...){ 14 | strex::str_before_nth(...) 15 | } 16 | 17 | #' @rdname str_before_nth 18 | #' @export 19 | str_before_first <- function(...){ 20 | strex::str_before_first(...) 21 | } 22 | 23 | #' @rdname str_before_nth 24 | #' @export 25 | before_first <- function(...){ 26 | strex::str_before_first(...) 27 | } 28 | 29 | #' @rdname str_before_nth 30 | #' @export 31 | str_before_last <- function(...){ 32 | strex::str_before_last(...) 33 | } 34 | 35 | #' @rdname str_before_nth 36 | #' @export 37 | before_last <- function(...){ 38 | strex::str_before_last(...) 39 | } 40 | 41 | 42 | #' Get the part of a string before the last period. 43 | #' 44 | #' Copy of [strex::str_before_last_dot()]. 45 | #' 46 | #' @inheritParams match_arg 47 | #' @export 48 | before_last_dot <- function(...){ 49 | strex::str_before_last_dot(...) 50 | } 51 | 52 | #' @rdname before_last_dot 53 | #' @export 54 | str_before_last_dot <- function(...){ 55 | strex::str_before_last_dot(...) 56 | } 57 | -------------------------------------------------------------------------------- /R/str-currency.R: -------------------------------------------------------------------------------- 1 | #' Get the currencies of numbers within a string. 2 | #' 3 | #' See [strex::str_extract_currencies()]. 4 | #' 5 | #' @name currency 6 | #' 7 | #' @inheritParams match_arg 8 | #' 9 | #' @export 10 | str_extract_currencies <- function(...){ 11 | strex::str_extract_currencies(...) 12 | } 13 | 14 | #' @rdname currency 15 | #' @export 16 | extract_currencies <- function(...){ 17 | strex::str_extract_currencies(...) 18 | } 19 | 20 | #' @rdname currency 21 | #' @export 22 | str_nth_currency <- function(...){ 23 | strex::str_nth_currency(...) 24 | } 25 | 26 | #' @rdname currency 27 | #' @export 28 | nth_currency <- function(...){ 29 | strex::str_nth_currency(...) 30 | } 31 | 32 | #' @rdname currency 33 | #' @export 34 | str_first_currency <- function(...){ 35 | strex::str_first_currency(...) 36 | } 37 | 38 | #' @rdname currency 39 | #' @export 40 | first_currency <- function(...){ 41 | strex::str_first_currency(...) 42 | } 43 | 44 | #' @rdname currency 45 | #' @export 46 | str_last_currency <- function(...){ 47 | strex::str_last_currency(...) 48 | } 49 | 50 | #' @rdname currency 51 | #' @export 52 | last_currency <- str_last_currency 53 | 54 | -------------------------------------------------------------------------------- /R/str-elem.R: -------------------------------------------------------------------------------- 1 | #' Extract a single character from a string, using its index. 2 | #' 3 | #' Copy of [strex::str_elem()]. 4 | #' 5 | #' @inheritParams match_arg 6 | #' 7 | #' @export 8 | str_elem <- function(...) { 9 | strex::str_elem(...) 10 | } 11 | 12 | #' @rdname str_elem 13 | #' @export 14 | elem <- str_elem 15 | 16 | #' Extract several single elements from a string. 17 | #' 18 | #' Copy of [strex::str_elems()]. 19 | #' 20 | #' @inheritParams match_arg 21 | #' 22 | #' @export 23 | str_elems <- function(...) { 24 | strex::str_elems(...) 25 | } 26 | 27 | #' @rdname str_elems 28 | #' @export 29 | elems <- str_elems 30 | 31 | #' Extract bits of a string and paste them together. 32 | #' 33 | #' Copy of [strex::str_paste_elems()]. 34 | #' 35 | #' @inheritParams match_arg 36 | #' 37 | #' @export 38 | str_paste_elems <- function(...) { 39 | strex::str_paste_elems(...) 40 | } 41 | 42 | #' @rdname str_paste_elems 43 | #' @export 44 | paste_elems <- str_paste_elems 45 | -------------------------------------------------------------------------------- /R/str-extract-non-nums.R: -------------------------------------------------------------------------------- 1 | #' Extract non-numbers from a string. 2 | #' 3 | #' Copies of [strex::str_extract_non_numerics()] and friends. 4 | #' 5 | #' @inheritParams match_arg 6 | #' 7 | #' @export 8 | extract_non_numerics <- function(...){ 9 | strex::str_extract_non_numerics(...) 10 | } 11 | 12 | #' @rdname extract_non_numerics 13 | #' @export 14 | str_extract_non_numerics <- extract_non_numerics 15 | 16 | #' @rdname extract_non_numerics 17 | #' @inheritParams strex::str_nth_non_numeric 18 | #' @export 19 | nth_non_numeric <- function(...){ 20 | strex::str_nth_non_numeric(...) 21 | } 22 | 23 | #' @rdname extract_non_numerics 24 | #' @export 25 | str_nth_non_numeric <- nth_non_numeric 26 | 27 | #' @rdname extract_non_numerics 28 | #' @export 29 | first_non_numeric <- function(...){ 30 | strex::str_first_non_numeric(...) 31 | } 32 | 33 | #' @rdname extract_non_numerics 34 | #' @export 35 | str_first_non_numeric <- first_non_numeric 36 | 37 | #' @rdname extract_non_numerics 38 | #' @export 39 | last_non_numeric <- function(...){ 40 | strex::str_last_non_numeric(...) 41 | } 42 | 43 | #' @rdname extract_non_numerics 44 | #' @export 45 | str_last_non_numeric <- last_non_numeric 46 | -------------------------------------------------------------------------------- /R/str-extract-nums.R: -------------------------------------------------------------------------------- 1 | #' Extract numbers from a string. 2 | #' 3 | #' Copies of [strex::str_extract_numbers()] and friends. 4 | #' 5 | #' @inheritParams match_arg 6 | #' 7 | #' @export 8 | extract_numbers <- function(...){ 9 | strex::str_extract_numbers(...) 10 | } 11 | 12 | #' @rdname extract_numbers 13 | #' @export 14 | str_extract_numbers <- extract_numbers 15 | 16 | #' @rdname extract_numbers 17 | #' @export 18 | nth_number <- function(...){ 19 | strex::str_nth_number(...) 20 | } 21 | 22 | #' @rdname extract_numbers 23 | #' @export 24 | str_nth_number <- nth_number 25 | 26 | #' @rdname extract_numbers 27 | #' @export 28 | first_number <- function(...){ 29 | strex::str_first_number(...) 30 | } 31 | 32 | #' @rdname extract_numbers 33 | #' @export 34 | str_first_number <- first_number 35 | 36 | #' @rdname extract_numbers 37 | #' @export 38 | last_number <- function(...){ 39 | strex::str_last_number(...) 40 | } 41 | 42 | #' @rdname extract_numbers 43 | #' @export 44 | str_last_number <- last_number 45 | -------------------------------------------------------------------------------- /R/str-give-ext.R: -------------------------------------------------------------------------------- 1 | #' Ensure a file name has the intended extension. 2 | #' 3 | #' Copy of [strex::str_give_ext()]. 4 | #' 5 | #' @inheritParams match_arg 6 | #' @export 7 | str_give_ext <- function(...) { 8 | strex::str_give_ext(...) 9 | } 10 | 11 | #' @rdname str_give_ext 12 | #' @export 13 | give_ext <- str_give_ext 14 | -------------------------------------------------------------------------------- /R/str-locate.R: -------------------------------------------------------------------------------- 1 | #' Locate the braces in a string. 2 | #' 3 | #' Copy of [strex::str_locate_braces()]. 4 | #' 5 | #' @inheritParams match_arg 6 | #' 7 | #' @export 8 | locate_braces <- function(...) { 9 | strex::str_locate_braces(...) 10 | } 11 | 12 | #' @rdname locate_braces 13 | #' @export 14 | str_locate_braces <- locate_braces 15 | 16 | #' Get the indices of the \eqn{n}th instance of a pattern. 17 | #' 18 | #' Copy of [strex::str_locate_nth()]. 19 | #' 20 | #' @inheritParams match_arg 21 | #' 22 | #' @export 23 | str_locate_nth <- function(...) { 24 | strex::str_locate_nth(...) 25 | } 26 | 27 | #' @rdname str_locate_nth 28 | #' @export 29 | locate_nth <- str_locate_nth 30 | 31 | #' @rdname str_locate_nth 32 | #' @export 33 | str_locate_first <- function(...) { 34 | strex::str_locate_first(...) 35 | } 36 | 37 | #' @rdname str_locate_nth 38 | #' @export 39 | locate_first <- str_locate_first 40 | 41 | #' @rdname str_locate_nth 42 | #' @export 43 | str_locate_last <- function(...) { 44 | strex::str_locate_last(...) 45 | } 46 | 47 | #' @rdname str_locate_nth 48 | #' @export 49 | locate_last <- str_locate_last 50 | -------------------------------------------------------------------------------- /R/str-nice-nums.R: -------------------------------------------------------------------------------- 1 | #' Make string numbers comply with alphabetical order. 2 | #' 3 | #' Copy of [strex::str_alphord_nums()]. 4 | #' 5 | #' @inheritParams match_arg 6 | #' @export 7 | str_nice_nums <- function(...) { 8 | strex::str_alphord_nums(...) 9 | } 10 | 11 | #' @rdname str_nice_nums 12 | #' @export 13 | nice_nums <- str_nice_nums 14 | 15 | #' @rdname str_nice_nums 16 | #' @export 17 | str_alphord_nums <- nice_nums 18 | 19 | #' @rdname str_nice_nums 20 | #' @export 21 | alphord_nums <- nice_nums 22 | -------------------------------------------------------------------------------- /R/str-num-after.R: -------------------------------------------------------------------------------- 1 | #' Find the `n`th number after the `m`th occurrence of a pattern. 2 | #' 3 | #' Copy of [strex::str_nth_number_after_mth()]. 4 | #' 5 | #' @inheritParams match_arg 6 | #' 7 | #' @export 8 | nth_number_after_mth <- function(...){ 9 | strex::str_nth_number_after_mth(...) 10 | } 11 | 12 | #' @rdname nth_number_after_mth 13 | #' @export 14 | str_nth_number_after_mth <- nth_number_after_mth 15 | 16 | #' @rdname nth_number_after_mth 17 | #' @export 18 | nth_number_after_first <- function(...){ 19 | strex::str_nth_number_after_first(...) 20 | } 21 | 22 | #' @rdname nth_number_after_mth 23 | #' @export 24 | nth_number_after_last <- function(...){ 25 | strex::str_nth_number_after_last(...) 26 | } 27 | 28 | #' @rdname nth_number_after_mth 29 | #' @export 30 | first_number_after_mth <- function(...){ 31 | strex::str_first_number_after_mth(...) 32 | } 33 | 34 | #' @rdname nth_number_after_mth 35 | #' @export 36 | last_number_after_mth <- function(...){ 37 | strex::str_last_number_after_mth(...) 38 | } 39 | 40 | #' @rdname nth_number_after_mth 41 | #' @export 42 | first_number_after_first <- function(...){ 43 | strex::str_first_number_after_first(...) 44 | } 45 | 46 | #' @rdname nth_number_after_mth 47 | #' @export 48 | first_number_after_last <- function(...){ 49 | strex::str_first_number_after_last(...) 50 | } 51 | 52 | #' @rdname nth_number_after_mth 53 | #' @export 54 | last_number_after_first <- function(...){ 55 | strex::str_last_number_after_first(...) 56 | } 57 | 58 | #' @rdname nth_number_after_mth 59 | #' @export 60 | last_number_after_last <- function(...){ 61 | strex::str_last_number_after_last(...) 62 | } 63 | 64 | #' @rdname nth_number_after_mth 65 | #' @export 66 | str_nth_number_after_first <- function(...){ 67 | strex::str_nth_number_after_first(...) 68 | } 69 | 70 | #' @rdname nth_number_after_mth 71 | #' @export 72 | str_nth_number_after_last <- function(...){ 73 | strex::str_nth_number_after_last(...) 74 | } 75 | 76 | #' @rdname nth_number_after_mth 77 | #' @export 78 | str_first_number_after_mth <- function(...){ 79 | strex::str_first_number_after_mth(...) 80 | } 81 | 82 | #' @rdname nth_number_after_mth 83 | #' @export 84 | str_last_number_after_mth <- function(...){ 85 | strex::str_last_number_after_mth(...) 86 | } 87 | 88 | #' @rdname nth_number_after_mth 89 | #' @export 90 | str_first_number_after_first <- function(...){ 91 | strex::str_first_number_after_first(...) 92 | } 93 | 94 | #' @rdname nth_number_after_mth 95 | #' @export 96 | str_first_number_after_last <- function(...){ 97 | strex::str_first_number_after_last(...) 98 | } 99 | 100 | #' @rdname nth_number_after_mth 101 | #' @export 102 | str_last_number_after_first <- function(...){ 103 | strex::str_last_number_after_first(...) 104 | } 105 | 106 | #' @rdname nth_number_after_mth 107 | #' @export 108 | str_last_number_after_last <- function(...){ 109 | strex::str_last_number_after_last(...) 110 | } 111 | -------------------------------------------------------------------------------- /R/str-num-before.R: -------------------------------------------------------------------------------- 1 | #' Find the `n`th number before the `m`th occurrence of a pattern. 2 | #' 3 | #' Copy of [strex::str_nth_number_before_mth()]. 4 | #' 5 | #' @inheritParams match_arg 6 | #' 7 | #' @export 8 | nth_number_before_mth <- function(...){ 9 | strex::str_nth_number_before_mth(...) 10 | } 11 | 12 | #' @rdname nth_number_before_mth 13 | #' @export 14 | str_nth_number_before_mth <- nth_number_before_mth 15 | 16 | #' @rdname nth_number_before_mth 17 | #' @export 18 | nth_number_before_first <- function(...){ 19 | strex::str_nth_number_before_first(...) 20 | } 21 | 22 | #' @rdname nth_number_before_mth 23 | #' @export 24 | nth_number_before_last <- function(...){ 25 | strex::str_nth_number_before_last(...) 26 | } 27 | 28 | #' @rdname nth_number_before_mth 29 | #' @export 30 | first_number_before_mth <- function(...){ 31 | strex::str_first_number_before_mth(...) 32 | } 33 | 34 | #' @rdname nth_number_before_mth 35 | #' @export 36 | last_number_before_mth <- function(...){ 37 | strex::str_last_number_before_mth(...) 38 | } 39 | 40 | #' @rdname nth_number_before_mth 41 | #' @export 42 | first_number_before_first <- function(...){ 43 | strex::str_first_number_before_first(...) 44 | } 45 | 46 | #' @rdname nth_number_before_mth 47 | #' @export 48 | first_number_before_last <- function(...){ 49 | strex::str_first_number_before_last(...) 50 | } 51 | 52 | #' @rdname nth_number_before_mth 53 | #' @export 54 | last_number_before_first <- function(...){ 55 | strex::str_last_number_before_first(...) 56 | } 57 | 58 | #' @rdname nth_number_before_mth 59 | #' @export 60 | last_number_before_last <- function(...){ 61 | strex::str_last_number_before_last(...) 62 | } 63 | 64 | #' @rdname nth_number_before_mth 65 | #' @export 66 | str_nth_number_before_first <- function(...){ 67 | strex::str_nth_number_before_first(...) 68 | } 69 | 70 | #' @rdname nth_number_before_mth 71 | #' @export 72 | str_nth_number_before_last <- function(...){ 73 | strex::str_nth_number_before_last(...) 74 | } 75 | 76 | #' @rdname nth_number_before_mth 77 | #' @export 78 | str_first_number_before_mth <- function(...){ 79 | strex::str_first_number_before_mth(...) 80 | } 81 | 82 | #' @rdname nth_number_before_mth 83 | #' @export 84 | str_last_number_before_mth <- function(...){ 85 | strex::str_last_number_before_mth(...) 86 | } 87 | 88 | #' @rdname nth_number_before_mth 89 | #' @export 90 | str_first_number_before_first <- function(...){ 91 | strex::str_first_number_before_first(...) 92 | } 93 | 94 | #' @rdname nth_number_before_mth 95 | #' @export 96 | str_first_number_before_last <- function(...){ 97 | strex::str_first_number_before_last(...) 98 | } 99 | 100 | #' @rdname nth_number_before_mth 101 | #' @export 102 | str_last_number_before_first <- function(...){ 103 | strex::str_last_number_before_first(...) 104 | } 105 | 106 | #' @rdname nth_number_before_mth 107 | #' @export 108 | str_last_number_before_last <- function(...){ 109 | strex::str_last_number_before_last(...) 110 | } 111 | -------------------------------------------------------------------------------- /R/str-pad.R: -------------------------------------------------------------------------------- 1 | #' Pad a character vector with empty strings. 2 | #' 3 | #' Extend a character vector by appending empty strings at the end. 4 | #' 5 | #' @param char_vec A character vector. The thing you wish to expand. 6 | #' @param extend_by A non-negative integer. By how much do you wish to extend 7 | #' the vector? 8 | #' @param length_out A positive integer. How long do you want the output vector 9 | #' to be? 10 | #' 11 | #' @return A character vector. 12 | #' 13 | #' @examples 14 | #' extend_char_vec(1:5, extend_by = 2) 15 | #' extend_char_vec(c("a", "b"), length_out = 10) 16 | #' @export 17 | extend_char_vec <- function(char_vec, extend_by = NA, length_out = NA) { 18 | checkmate::assert_int(extend_by, na.ok = TRUE) 19 | if (is.na(extend_by) && is.na(length_out)) { 20 | stop("One of extend.by or length.out must be specified.") 21 | } 22 | checkmate::assert_atomic(char_vec) 23 | if (is.numeric(char_vec)) char_vec %<>% as.character() 24 | checkmate::assert_character(char_vec) 25 | if (!is.na(extend_by)) { 26 | return(c(char_vec, rep("", extend_by))) 27 | } 28 | if (!is.na(length_out)) { 29 | if (!(is.numeric(length_out) && length_out >= length(char_vec))) { 30 | stop( 31 | "If specified, length.out must be numeric and at least equal to ", 32 | "the length of char.vec." 33 | ) 34 | } 35 | c(char_vec, rep("", length_out - length(char_vec))) 36 | } 37 | } 38 | 39 | #' @rdname extend_char_vec 40 | #' @export 41 | str_extend_char_vec <- extend_char_vec 42 | -------------------------------------------------------------------------------- /R/str-put-in-pos.R: -------------------------------------------------------------------------------- 1 | #' Put specified strings in specified positions in an otherwise empty character 2 | #' vector. 3 | #' 4 | #' Create a character vector with a set of strings at specified positions in 5 | #' that character vector, with the rest of it taken up by empty strings. 6 | #' @param strings A character vector of the strings to put in positions 7 | #' (coerced by [as.character] if not character already). 8 | #' @param positions The indices of the character vector to be occupied by the 9 | #' elements of strings. Must be the same length as strings or of length 1. 10 | #' @return A character vector. 11 | #' @examples 12 | #' put_in_pos(1:3, c(1, 8, 9)) 13 | #' put_in_pos(c("Apple", "Orange", "County"), c(5, 7, 8)) 14 | #' put_in_pos(1:2, 5) 15 | #' @export 16 | put_in_pos <- function(strings, positions) { 17 | ls <- length(strings) 18 | if (ls > 1 && length(positions) == 1) { 19 | positions <- positions:(positions + ls - 1) 20 | } 21 | strings <- as.character(strings) 22 | stopifnot(length(strings) == length(positions)) 23 | out <- rep("", max(positions)) 24 | out[positions] <- strings 25 | out 26 | } 27 | 28 | #' @rdname put_in_pos 29 | #' @export 30 | str_put_in_pos <- put_in_pos 31 | -------------------------------------------------------------------------------- /R/str-remove.R: -------------------------------------------------------------------------------- 1 | #' Remove the quoted parts of a string. 2 | #' 3 | #' Copy of [strex::str_remove_quoted()]. 4 | #' 5 | #' @inheritParams match_arg 6 | #' 7 | #' @export 8 | str_remove_quoted <- function(...) { 9 | strex::str_remove_quoted(...) 10 | } 11 | 12 | #' @rdname str_remove_quoted 13 | #' @export 14 | remove_quoted <- str_remove_quoted 15 | -------------------------------------------------------------------------------- /R/str-singleize.R: -------------------------------------------------------------------------------- 1 | #' Remove back-to-back duplicates of a pattern in a string. 2 | #' 3 | #' Copy of [strex::str_singleize()]. 4 | #' 5 | #' @inheritParams match_arg 6 | #' 7 | #' @export 8 | str_singleize <- function(...){ 9 | strex::str_singleize(...) 10 | } 11 | 12 | #' @rdname str_singleize 13 | #' @export 14 | singleize <- str_singleize 15 | -------------------------------------------------------------------------------- /R/str-split-by-nums.R: -------------------------------------------------------------------------------- 1 | #' Split a string by its numeric characters. 2 | #' 3 | #' Copy of [strex::str_split_by_numbers()]. 4 | #' 5 | #' @inheritParams match_arg 6 | #' 7 | #' @export 8 | str_split_by_nums <- function(...) { 9 | strex::str_split_by_numbers(...) 10 | } 11 | 12 | #' @rdname str_split_by_nums 13 | #' @export 14 | split_by_nums <- str_split_by_nums 15 | 16 | #' @rdname str_split_by_nums 17 | #' @export 18 | split_by_numbers <- str_split_by_nums 19 | 20 | #' @rdname str_split_by_nums 21 | #' @export 22 | str_split_by_numbers <- str_split_by_nums 23 | -------------------------------------------------------------------------------- /R/str-split.R: -------------------------------------------------------------------------------- 1 | #' Split a string based on CamelCase 2 | #' 3 | #' See [strex::str_split_camel_case()]. 4 | #' 5 | #' @inheritParams strex::str_split_camel_case 6 | #' 7 | #' @export 8 | str_split_camel_case <- strex::str_split_camel_case 9 | 10 | #' @rdname str_split_camel_case 11 | #' @export 12 | split_camel_case <- str_split_camel_case 13 | -------------------------------------------------------------------------------- /R/str-to-vec.R: -------------------------------------------------------------------------------- 1 | #' Convert a string to a vector of characters 2 | #' 3 | #' Copy of [strex::str_to_vec()]. 4 | #' 5 | #' @inheritParams match_arg 6 | #' 7 | #' @export 8 | str_to_vec <- function(...) { 9 | strex::str_to_vec(...) 10 | } 11 | 12 | #' @rdname str_to_vec 13 | #' @export 14 | to_vec <- str_to_vec 15 | -------------------------------------------------------------------------------- /R/str-trim.R: -------------------------------------------------------------------------------- 1 | #' Trim something other than whitespace. 2 | #' 3 | #' Copy of [strex::str_trim_anything()]. 4 | #' 5 | #' @inheritParams match_arg 6 | #' 7 | #' @export 8 | str_trim_anything <- function(...){ 9 | strex::str_trim_anything(...) 10 | } 11 | 12 | #' @rdname str_trim_anything 13 | #' @export 14 | trim_anything <- str_trim_anything 15 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | #' Group together close adjacent elements of a vector. 2 | #' 3 | #' Given a strictly increasing vector (each element is bigger than the last), 4 | #' group together stretches of the vector where *adjacent* elements are 5 | #' separated by at most some specified distance. Hence, each element in each 6 | #' group has at least one other element in that group that is *close* to 7 | #' it. See the examples. 8 | #' @param vec_ascending A strictly increasing numeric vector. 9 | #' @param max_gap The biggest allowable gap between adjacent elements for them 10 | #' to be considered part of the same *group*. 11 | #' @return A where each element is one group, as a numeric vector. 12 | #' @examples 13 | #' group_close(1:10, 1) 14 | #' group_close(1:10, 0.5) 15 | #' group_close(c(1, 2, 4, 10, 11, 14, 20, 25, 27), 3) 16 | #' @export 17 | group_close <- function(vec_ascending, max_gap = 1) { 18 | lv <- length(vec_ascending) 19 | if (lv == 0) stop("vec_ascending must have length greater than zero.") 20 | test <- all(diff(vec_ascending) > 0) 21 | if (is.na(test) || !test) stop("vec_ascending must be strictly increasing.") 22 | if (lv == 1) { 23 | return(list(vec_ascending)) 24 | } else { 25 | gaps <- vec_ascending[2:lv] - vec_ascending[1:(lv - 1)] 26 | big_gaps <- gaps > max_gap 27 | nbgaps <- sum(big_gaps) # number of big gaps 28 | if (!nbgaps) { 29 | return(list(vec_ascending)) 30 | } else { 31 | ends <- which(big_gaps) # vertical end of lines 32 | group1 <- vec_ascending[1:ends[1]] 33 | lg <- list(group1) 34 | if (nbgaps == 1) { 35 | lg[[2]] <- vec_ascending[(ends[1] + 1):lv] 36 | } else { 37 | for (i in 2:nbgaps) { 38 | lg[[i]] <- vec_ascending[(ends[i - 1] + 1):ends[i]] 39 | ikeep <- i 40 | } 41 | lg[[ikeep + 1]] <- vec_ascending[(ends[nbgaps] + 1):lv] 42 | } 43 | return(lg) 44 | } 45 | } 46 | } 47 | 48 | is_l0_char <- function(x) isTRUE(checkmate::check_character(x, max.len = 0)) 49 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | # filesstrings 7 | 8 | ```{r setup, include=FALSE} 9 | knitr::opts_chunk$set(echo = TRUE, comment = "#>") 10 | ``` 11 | 12 | This started out as a package for file and string manipulation. Since then, the `fs` file manipulation package and the `strex string manipulation package 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](https://cran.r-project.org/package=filesstrings/vignettes/files.html). One example is a function to remove spaces from all file names in a directory. 13 | 14 | [![R-CMD-check](https://github.com/rorynolan/filesstrings/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rorynolan/filesstrings/actions/workflows/R-CMD-check.yaml) 15 | [![Codecov test coverage](https://codecov.io/gh/rorynolan/filesstrings/branch/master/graph/badge.svg)](https://app.codecov.io/gh/rorynolan/filesstrings?branch=master) 16 | 17 | [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html) 18 | [![Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.](https://www.repostatus.org/badges/latest/inactive.svg)](https://www.repostatus.org/#inactive) 19 | 20 | [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/filesstrings)](https://cran.r-project.org/package=filesstrings) 21 | ![RStudio CRAN downloads](http://cranlogs.r-pkg.org/badges/grand-total/filesstrings) 22 | ![RStudio CRAN monthly downloads](http://cranlogs.r-pkg.org/badges/filesstrings) 23 | 24 | [![JOSS publication](http://joss.theoj.org/papers/10.21105/joss.00260/status.svg)](https://doi.org/10.21105/joss.00260) 25 | [![DOI](https://zenodo.org/badge/69170704.svg)](https://zenodo.org/badge/latestdoi/69170704) 26 | 27 | 28 | # Installation 29 | 30 | To install the release version of `filesstrings` from [CRAN](https://cran.r-project.org/package=filesstrings), in R, enter 31 | ```{r Install filesstrings, eval=FALSE} 32 | install.packages("filesstrings") 33 | ``` 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # filesstrings 3 | 4 | This started out as a package for file and string manipulation. Since 5 | then, the `fs` file manipulation package and the \`strex string 6 | manipulation package emerged, offering functionality previously given by 7 | this package (but slightly better). Those packages have hence almost 8 | pushed ‘filesstrings’ into extinction. However, it still has a small 9 | number of unique, handy file manipulation functions which can be seen in 10 | the 11 | [vignette](https://cran.r-project.org/package=filesstrings/vignettes/files.html). 12 | One example is a function to remove spaces from all file names in a 13 | directory. 14 | 15 | [![R-CMD-check](https://github.com/rorynolan/filesstrings/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rorynolan/filesstrings/actions/workflows/R-CMD-check.yaml) 16 | [![Codecov test 17 | coverage](https://codecov.io/gh/rorynolan/filesstrings/branch/master/graph/badge.svg)](https://app.codecov.io/gh/rorynolan/filesstrings?branch=master) 18 | 19 | [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html) 20 | [![Project Status: Inactive – The project has reached a stable, usable 21 | state but is no longer being actively developed; support/maintenance 22 | will be provided as time 23 | allows.](https://www.repostatus.org/badges/latest/inactive.svg)](https://www.repostatus.org/#inactive) 24 | 25 | [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/filesstrings)](https://cran.r-project.org/package=filesstrings) 26 | ![RStudio CRAN 27 | downloads](http://cranlogs.r-pkg.org/badges/grand-total/filesstrings) 28 | ![RStudio CRAN monthly 29 | downloads](http://cranlogs.r-pkg.org/badges/filesstrings) 30 | 31 | [![JOSS 32 | publication](http://joss.theoj.org/papers/10.21105/joss.00260/status.svg)](https://doi.org/10.21105/joss.00260) 33 | [![DOI](https://zenodo.org/badge/69170704.svg)](https://zenodo.org/badge/latestdoi/69170704) 34 | 35 | # Installation 36 | 37 | To install the release version of `filesstrings` from 38 | [CRAN](https://cran.r-project.org/package=filesstrings), in R, enter 39 | 40 | ``` r 41 | install.packages("filesstrings") 42 | ``` 43 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /codemeta.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": "https://doi.org/10.5063/schema/codemeta-2.0", 3 | "@type": "SoftwareSourceCode", 4 | "identifier": "filesstrings", 5 | "description": "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.", 6 | "name": "filesstrings: Handy File and String Manipulation", 7 | "relatedLink": ["https://rorynolan.github.io/filesstrings/", "https://CRAN.R-project.org/package=filesstrings"], 8 | "codeRepository": "https://github.com/rorynolan/filesstrings", 9 | "issueTracker": "https://github.com/rorynolan/filesstrings/issues", 10 | "license": "https://spdx.org/licenses/GPL-3.0", 11 | "version": "3.4.0", 12 | "programmingLanguage": { 13 | "@type": "ComputerLanguage", 14 | "name": "R", 15 | "url": "https://r-project.org" 16 | }, 17 | "runtimePlatform": "R version 4.3.2 (2023-10-31)", 18 | "provider": { 19 | "@id": "https://cran.r-project.org", 20 | "@type": "Organization", 21 | "name": "Comprehensive R Archive Network (CRAN)", 22 | "url": "https://cran.r-project.org" 23 | }, 24 | "author": [ 25 | { 26 | "@type": "Person", 27 | "givenName": "Rory", 28 | "familyName": "Nolan", 29 | "email": "rorynoolan@gmail.com", 30 | "@id": "https://orcid.org/0000-0002-5239-4043" 31 | } 32 | ], 33 | "contributor": [ 34 | { 35 | "@type": "Person", 36 | "givenName": "Sergi", 37 | "familyName": "Padilla-Parra", 38 | "email": "spadilla@well.ox.ac.uk", 39 | "@id": "https://orcid.org/0000-0002-8010-9481" 40 | } 41 | ], 42 | "copyrightHolder": [ 43 | { 44 | "@type": "Person", 45 | "givenName": "Rory", 46 | "familyName": "Nolan", 47 | "email": "rorynoolan@gmail.com", 48 | "@id": "https://orcid.org/0000-0002-5239-4043" 49 | } 50 | ], 51 | "maintainer": [ 52 | { 53 | "@type": "Person", 54 | "givenName": "Rory", 55 | "familyName": "Nolan", 56 | "email": "rorynoolan@gmail.com", 57 | "@id": "https://orcid.org/0000-0002-5239-4043" 58 | } 59 | ], 60 | "softwareSuggestions": [ 61 | { 62 | "@type": "SoftwareApplication", 63 | "identifier": "covr", 64 | "name": "covr", 65 | "provider": { 66 | "@id": "https://cran.r-project.org", 67 | "@type": "Organization", 68 | "name": "Comprehensive R Archive Network (CRAN)", 69 | "url": "https://cran.r-project.org" 70 | }, 71 | "sameAs": "https://CRAN.R-project.org/package=covr" 72 | }, 73 | { 74 | "@type": "SoftwareApplication", 75 | "identifier": "dplyr", 76 | "name": "dplyr", 77 | "provider": { 78 | "@id": "https://cran.r-project.org", 79 | "@type": "Organization", 80 | "name": "Comprehensive R Archive Network (CRAN)", 81 | "url": "https://cran.r-project.org" 82 | }, 83 | "sameAs": "https://CRAN.R-project.org/package=dplyr" 84 | }, 85 | { 86 | "@type": "SoftwareApplication", 87 | "identifier": "knitr", 88 | "name": "knitr", 89 | "provider": { 90 | "@id": "https://cran.r-project.org", 91 | "@type": "Organization", 92 | "name": "Comprehensive R Archive Network (CRAN)", 93 | "url": "https://cran.r-project.org" 94 | }, 95 | "sameAs": "https://CRAN.R-project.org/package=knitr" 96 | }, 97 | { 98 | "@type": "SoftwareApplication", 99 | "identifier": "rmarkdown", 100 | "name": "rmarkdown", 101 | "provider": { 102 | "@id": "https://cran.r-project.org", 103 | "@type": "Organization", 104 | "name": "Comprehensive R Archive Network (CRAN)", 105 | "url": "https://cran.r-project.org" 106 | }, 107 | "sameAs": "https://CRAN.R-project.org/package=rmarkdown" 108 | }, 109 | { 110 | "@type": "SoftwareApplication", 111 | "identifier": "spelling", 112 | "name": "spelling", 113 | "provider": { 114 | "@id": "https://cran.r-project.org", 115 | "@type": "Organization", 116 | "name": "Comprehensive R Archive Network (CRAN)", 117 | "url": "https://cran.r-project.org" 118 | }, 119 | "sameAs": "https://CRAN.R-project.org/package=spelling" 120 | }, 121 | { 122 | "@type": "SoftwareApplication", 123 | "identifier": "testthat", 124 | "name": "testthat", 125 | "version": ">= 2.1", 126 | "provider": { 127 | "@id": "https://cran.r-project.org", 128 | "@type": "Organization", 129 | "name": "Comprehensive R Archive Network (CRAN)", 130 | "url": "https://cran.r-project.org" 131 | }, 132 | "sameAs": "https://CRAN.R-project.org/package=testthat" 133 | } 134 | ], 135 | "softwareRequirements": { 136 | "1": { 137 | "@type": "SoftwareApplication", 138 | "identifier": "R", 139 | "name": "R", 140 | "version": ">= 3.5" 141 | }, 142 | "2": { 143 | "@type": "SoftwareApplication", 144 | "identifier": "stringr", 145 | "name": "stringr", 146 | "version": ">= 1.5", 147 | "provider": { 148 | "@id": "https://cran.r-project.org", 149 | "@type": "Organization", 150 | "name": "Comprehensive R Archive Network (CRAN)", 151 | "url": "https://cran.r-project.org" 152 | }, 153 | "sameAs": "https://CRAN.R-project.org/package=stringr" 154 | }, 155 | "3": { 156 | "@type": "SoftwareApplication", 157 | "identifier": "checkmate", 158 | "name": "checkmate", 159 | "version": ">= 1.9.3", 160 | "provider": { 161 | "@id": "https://cran.r-project.org", 162 | "@type": "Organization", 163 | "name": "Comprehensive R Archive Network (CRAN)", 164 | "url": "https://cran.r-project.org" 165 | }, 166 | "sameAs": "https://CRAN.R-project.org/package=checkmate" 167 | }, 168 | "4": { 169 | "@type": "SoftwareApplication", 170 | "identifier": "magrittr", 171 | "name": "magrittr", 172 | "version": ">= 1.5", 173 | "provider": { 174 | "@id": "https://cran.r-project.org", 175 | "@type": "Organization", 176 | "name": "Comprehensive R Archive Network (CRAN)", 177 | "url": "https://cran.r-project.org" 178 | }, 179 | "sameAs": "https://CRAN.R-project.org/package=magrittr" 180 | }, 181 | "5": { 182 | "@type": "SoftwareApplication", 183 | "identifier": "purrr", 184 | "name": "purrr", 185 | "version": ">= 0.3.0", 186 | "provider": { 187 | "@id": "https://cran.r-project.org", 188 | "@type": "Organization", 189 | "name": "Comprehensive R Archive Network (CRAN)", 190 | "url": "https://cran.r-project.org" 191 | }, 192 | "sameAs": "https://CRAN.R-project.org/package=purrr" 193 | }, 194 | "6": { 195 | "@type": "SoftwareApplication", 196 | "identifier": "rlang", 197 | "name": "rlang", 198 | "version": ">= 0.3.3", 199 | "provider": { 200 | "@id": "https://cran.r-project.org", 201 | "@type": "Organization", 202 | "name": "Comprehensive R Archive Network (CRAN)", 203 | "url": "https://cran.r-project.org" 204 | }, 205 | "sameAs": "https://CRAN.R-project.org/package=rlang" 206 | }, 207 | "7": { 208 | "@type": "SoftwareApplication", 209 | "identifier": "strex", 210 | "name": "strex", 211 | "version": ">= 1.6", 212 | "provider": { 213 | "@id": "https://cran.r-project.org", 214 | "@type": "Organization", 215 | "name": "Comprehensive R Archive Network (CRAN)", 216 | "url": "https://cran.r-project.org" 217 | }, 218 | "sameAs": "https://CRAN.R-project.org/package=strex" 219 | }, 220 | "8": { 221 | "@type": "SoftwareApplication", 222 | "identifier": "stringi", 223 | "name": "stringi", 224 | "version": ">= 1.7.8", 225 | "provider": { 226 | "@id": "https://cran.r-project.org", 227 | "@type": "Organization", 228 | "name": "Comprehensive R Archive Network (CRAN)", 229 | "url": "https://cran.r-project.org" 230 | }, 231 | "sameAs": "https://CRAN.R-project.org/package=stringi" 232 | }, 233 | "9": { 234 | "@type": "SoftwareApplication", 235 | "identifier": "withr", 236 | "name": "withr", 237 | "version": ">= 2.1.0", 238 | "provider": { 239 | "@id": "https://cran.r-project.org", 240 | "@type": "Organization", 241 | "name": "Comprehensive R Archive Network (CRAN)", 242 | "url": "https://cran.r-project.org" 243 | }, 244 | "sameAs": "https://CRAN.R-project.org/package=withr" 245 | }, 246 | "SystemRequirements": null 247 | }, 248 | "fileSize": "822.565KB", 249 | "citation": [ 250 | { 251 | "@type": "ScholarlyArticle", 252 | "datePublished": "2017", 253 | "author": [ 254 | { 255 | "@type": "Person", 256 | "givenName": "Rory", 257 | "familyName": "Nolan" 258 | }, 259 | { 260 | "@type": "Person", 261 | "givenName": "Sergi", 262 | "familyName": "Padilla-Parra" 263 | } 264 | ], 265 | "name": "{filesstrings}: An R package for file and string manipulation", 266 | "identifier": "10.21105/joss.00260", 267 | "@id": "https://doi.org/10.21105/joss.00260", 268 | "sameAs": "https://doi.org/10.21105/joss.00260", 269 | "isPartOf": { 270 | "@type": "PublicationIssue", 271 | "issueNumber": "14", 272 | "datePublished": "2017", 273 | "isPartOf": { 274 | "@type": ["PublicationVolume", "Periodical"], 275 | "volumeNumber": "2", 276 | "name": "The Journal of Open Source Software" 277 | } 278 | } 279 | } 280 | ], 281 | "releaseNotes": "https://github.com/rorynolan/filesstrings/blob/master/NEWS.md", 282 | "readme": "https://github.com/rorynolan/filesstrings/blob/master/README.md", 283 | "contIntegration": ["https://github.com/rorynolan/filesstrings/actions/workflows/R-CMD-check.yaml", "https://app.codecov.io/gh/rorynolan/filesstrings?branch=master"], 284 | "developmentStatus": ["https://lifecycle.r-lib.org/articles/stages.html", "https://www.repostatus.org/#inactive"] 285 | } 286 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Reverse Dependencies 2 | We checked the reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. 3 | * We saw 0 new problems 4 | * We failed to check 0 packages 5 | -------------------------------------------------------------------------------- /filesstrings.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | bibentry(bibtype = "Article", 2 | title = "{filesstrings}: An R package for file and string manipulation", 3 | author = c(as.person("Rory Nolan"), as.person("Sergi Padilla-Parra")), 4 | journal = "The Journal of Open Source Software", 5 | year = "2017", 6 | volume = "2", 7 | number = "14", 8 | doi = "10.21105/joss.00260" 9 | ) 10 | -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | CMD 2 | CamelCase 3 | DOI 4 | Giorgio 5 | JOSS 6 | Parra 7 | README 8 | RStudio 9 | Spedicato's 10 | behaviour 11 | codecov 12 | filesstrings’ 13 | fs 14 | integerish 15 | lifecycle 16 | organised 17 | readr 18 | strex 19 | stringi 20 | th 21 | tidyverse 22 | -------------------------------------------------------------------------------- /junk/Files.R: -------------------------------------------------------------------------------- 1 | require(stringr) 2 | 3 | ArgName <- function(x) deparse(substitute(x)) 4 | AsNumeric <- function(arg) suppressWarnings(as.numeric(arg)) 5 | CanBeNumeric <- function(string) !is.na(AsNumeric(string)) 6 | CharVec <- function(string) strsplit(string, NULL)[[1]] 7 | DirCreateIfNotThere <- function(dir.name) if (!file.exists(dir.name)) dir.create(dir.name) 8 | DirRemove <- function(dir) unlink(dir, recursive = T) 9 | DirMove <- function(dir, destination) { 10 | file.copy(dir, destination, recursive = T, overwrite = T) 11 | DirRemove(dir) 12 | } 13 | DirsMove <- function(dirs, destinations) { 14 | if(length(destinations) == length(dirs)) { 15 | mapply(DirMove, dirs, destinations) 16 | } else if (length(destinations == 1)) { 17 | sapply(dirs, DirMove, destinations) 18 | } else { 19 | stop("the number of destinations must be equal to 1 or equal to the number of directories to be moved") 20 | } 21 | } 22 | ExtractMatFrom3DArray <- function(array3D, slice) array3D[, , slice] 23 | FirstNumber <- function(string, leave.as.string = F) { 24 | char.vec <- sapply(1:nchar(string), StrElem, string = string) 25 | first.numeric <- match(F, is.na(AsNumeric(char.vec))) 26 | non.numeric.start.gone <- substr(string, first.numeric, nchar(string)) 27 | first.number <- LeadingNumber(non.numeric.start.gone, leave.as.string) 28 | return(first.number) 29 | } 30 | GoToDirAndGetImList <- function(dir.fromhere, pat = "\\.tif", z = 0) { 31 | initial.dir <- getwd() 32 | setwd(goto.dir) 33 | im.list <- ImMatListFromNamePattern(pat, z) 34 | names(rim.list) <- sapply(names(rim.list), RemoveDotTif) 35 | setwd(initial.dir) 36 | return(rim.list) 37 | } 38 | Grouper <- function(vai, max.gap = 1){ # VectorofAscendingIndices 39 | # groups together bright rows of the matrix which represent the same "line" 40 | lv <- length(vai) 41 | if (lv == 0) stop("no lines of desired length found") 42 | if (lv == 1) { 43 | return(list(vai)) 44 | } else { 45 | gaps <- vai[2:lv] - vai[1:(lv-1)] 46 | big.gaps <- gaps > max.gap 47 | nbgaps <- sum(big.gaps) # number of big (>10) gaps 48 | if (!nbgaps) { 49 | return(list(vai)) 50 | } else { 51 | ends <- which(big.gaps) # vertical end of lines 52 | group1 <- vai[1:ends[1]] 53 | lg <- list(group1) 54 | if (nbgaps == 1){ 55 | lg[[2]] <- vai[(ends[1] + 1):lv] 56 | } else { 57 | for (i in 2:nbgaps){ 58 | lg[[i]] <- vai[(ends[i - 1] + 1):ends[i]] 59 | ikeep <- i 60 | } 61 | lg[[ikeep + 1]] <- vai[(ends[nbgaps] + 1):lv] 62 | } 63 | return(lg) 64 | } 65 | } 66 | } 67 | ImMatListFromNamePattern <- function(name.patterns, z = 0, first.last = 0) { 68 | # Read in a list of image matrices as in RIM where only images with names containing the strings specified in the string vector name.patterns are read into the list 69 | name.matches <- StringsWithPatterns(list.files(), name.patterns) 70 | if (first.last != 0) { 71 | if (!first.last %in% c("first", "f", "last", "l")) { 72 | stop('if first.last is set, it must be either "first", "f", "last" or "l"') 73 | } else { 74 | if (first.last %in% c("first", "f")) nums <- sapply(name.matches, FirstNumber) 75 | if (first.last %in% c("last", "l")) nums <- sapply(name.matches, LastNumber) 76 | name.matches <- name.matches[order(nums)] 77 | } 78 | } 79 | img.mat.list <- lapply(name.matches, RIM, z, fix4to3) 80 | names(img.mat.list) <- name.matches 81 | return(img.mat.list) 82 | } 83 | ImStack2GrayscaleList <- function(img.stack) { 84 | z.slices <- 1:(dim(img.stack)[3]) 85 | gray.list <- lapply(z.slices, ExtractMatFrom3DArray, array3D = img.stack) 86 | } 87 | Interleave <- function(vec1, vec2) { 88 | l1 <- length(vec1) 89 | l2 <- length(vec2) 90 | if (! (l1 - l2) %in% 0:1) stop("vec1 must be either the same length as vec2 or one longer than it") 91 | ans <- 1:(l1 + l2) 92 | ans[seq(1, 2 * l1 - 1, 2)] <- vec1 93 | ans[seq(2, 2 * l2, 2)] <- vec2 94 | return(ans) 95 | } 96 | ListDirs <- function(pattern = NA, ord = F) { 97 | dirs <- setdiff(list.files(), list.files(pattern = "\\.")) 98 | if (ord) { 99 | fns <- sapply(dirs, FirstNumber) 100 | lns <- sapply(dirs, LastNumber) 101 | ordr <- OrderOnAThenB(fns, lns) 102 | ordered.dirs <- dirs[ordr] 103 | dirs <- ordered.dirs 104 | } 105 | if (!is.na(pattern)) { 106 | dirs <- dirs[grepl(pattern, dirs)] 107 | } 108 | return(dirs) 109 | } 110 | LFNO <- function(pattern = -1) { # List_Files_Number_Order 111 | if (pattern == -1) { 112 | lf <- list.files() 113 | } else { 114 | lf <- list.files(pattern = pattern) 115 | } 116 | ord <- order(sapply(lf, FirstNumber)) 117 | return(lf[ord]) 118 | } 119 | LastNChars <- function(string, n) { 120 | char.vec <- CharVec(string) 121 | l <- length(char.vec) 122 | start <- l - n + 1 123 | char.vec <- char.vec[start:l] 124 | last.n <- paste(char.vec, collapse = "") 125 | return(last.n) 126 | } 127 | LastNumber <- function(string, leave.as.string = F) { 128 | # this function doesn't work for strings with decimal numbers 129 | string.reversed <- StrReverse(string) 130 | last.num.backwards.string <- FirstNumber(string.reversed, leave.as.string = T) 131 | last.num.string <- StrReverse(last.num.backwards.string) 132 | if (leave.as.string) { 133 | return(last.num.string) 134 | } else { 135 | last.num <- as.numeric(last.num.string) 136 | return(last.num) 137 | } 138 | } 139 | LeadingNumber <- function(string, leave.as.string = F) { 140 | # this function doesn't work for strings with decimal numbers 141 | if (!is.na(suppressWarnings(as.numeric(string)))) { 142 | if (leave.as.string) { 143 | return(toString(string)) 144 | } else { 145 | return(as.numeric(string)) 146 | } 147 | } else if (is.na(suppressWarnings(as.numeric(StrElem(string, 1))))) { 148 | stop("string does not begin with a numeric character") 149 | } else { 150 | char.vec <- sapply(1:nchar(string), StrElem, string = string) 151 | suppressWarnings(numeric.or.not <- sapply(char.vec, as.numeric)) 152 | last.numeric <- match(NA, numeric.or.not) - 1 153 | number.as.string <- substr(string, 1, last.numeric) 154 | if (leave.as.string) { 155 | return(number.as.string) 156 | } else { 157 | number <- as.numeric(number.as.string) 158 | return(number) 159 | } 160 | } 161 | } 162 | MergeCSVs <- function(out.name = "Merged_CSVs", header = T, saf = F) { 163 | ext <- ".csv" 164 | lcsvs <- list.files(pattern = ext) 165 | if (LastNChars(out.name, 4) != ext) out.name <- paste0(out.name, ext) 166 | tables <- lapply(lcsvs, ReadCSV, header = header, saf = saf) 167 | ncs <- sapply(tables, ncol) 168 | if (!MyAllEqual(ncs)) stop("The csvs have different numbers of columns.") 169 | merged <- Reduce(rbind, tables) 170 | write.csv(merged, file = out.name) 171 | } 172 | MyAllEqual <- function(a, b = NA, cn = F) { 173 | if (is.na(b[1])) { 174 | return(length(unique(a)) == 1) 175 | } else { 176 | return(isTRUE(all.equal(a, b, check.names = cn))) 177 | } 178 | } 179 | Mat2RowList <- function(mat) { 180 | # convert a matrix into a list where each list element is a row of that matrix 181 | RowList <- split(t(mat), rep(1:ncol(t(mat)), each=nrow(t(mat)))) 182 | return(RowList) 183 | } 184 | Mat2ColList <- function(mat) { 185 | # convert a matrix into a list where each list element is a column of that matrix 186 | RowList <- split(mat, rep(1:ncol(mat), each=nrow(mat))) 187 | return(RowList) 188 | } 189 | NiceFileNums <- function(patt = NA) { 190 | if (is.na(patt)) { 191 | lf <- list.files() 192 | } else { 193 | lf <- list.files(pattern = patt) 194 | } 195 | file.nums <- lapply(lf, NumsSepByStrings) 196 | if (!MyAllEqual(sapply(file.nums, length))) stop("some of the file names contain different numbers of numbers") 197 | file.nums <- simplify2array(file.nums) 198 | if (is.vector(file.nums)) file.nums <- t(as.matrix(file.nums)) 199 | max.lengths <- apply(file.nums, 1, function(x) max(nchar(x))) 200 | for (i in 1:nrow(file.nums)) { 201 | for (j in 1:ncol(file.nums)) { 202 | while(nchar(file.nums[i, j]) < max.lengths[i]) { 203 | file.nums[i, j] <- paste0(0, file.nums[i, j]) 204 | } 205 | } 206 | } 207 | num.first <- sapply(lf, function(x) CanBeNumeric(StrElem(x, 1))) 208 | if (!MyAllEqual(num.first)) stop("some file names start with numbers and some don't") 209 | numbers <- Mat2ColList(file.nums) 210 | strings <- lapply(lf, StringsSepByNums) 211 | if (num.first[1]) { 212 | interleaves <- mapply(Interleave, numbers, strings) 213 | } else { 214 | interleaves <- mapply(Interleave, strings, numbers) 215 | } 216 | new.names <- apply(interleaves, 2, function(x) paste(x, collapse = "")) 217 | file.rename(lf, new.names) 218 | } 219 | NthNumber <- function(string, n) { 220 | # this function doesn't work for strings with decimal numbers 221 | for (i in 1:(n - 1)) { 222 | fn <- FirstNumber(string, T) 223 | string <- str_replace(string, fn, "") 224 | } 225 | return(FirstNumber(string)) 226 | } 227 | NumsSepByStrings <- function(string) { 228 | # this function doesn't work for strings with decimal numbers 229 | numeric.chars <- which(CanBeNumeric(CharVec(string))) 230 | numeric.groups <- Grouper(numeric.chars) 231 | numerics <- sapply(numeric.groups, StrElemsPasted, string = string) # these will not be of numeric type, just of the type that will come out of as.numeric as numbers and not NAs 232 | return(numerics) 233 | } 234 | PutFilesInDir <- function(file.names, dir.name) { 235 | DirCreateIfNotThere(dir.name) 236 | there <- paste0(getwd(), "/", dir.name) 237 | new.names <- str_replace_all(paste0(there, "/", file.names), " ", "") 238 | file.rename(file.names, new.names) 239 | } 240 | ReadCSV <- function(file, header = T, saf = F) { 241 | if (LastNChars(file, 4) != ".csv") file <- paste0(file, ".csv") 242 | x <- CharVec(readLines(file, 1))[1:3] 243 | if (all(x == c("\"", "\"", ","))) { 244 | return(read.csv(file, header = header, row.names = 1, stringsAsFactors = saf)) 245 | } else { 246 | return(read.csv(file, header = header, stringsAsFactors = saf)) 247 | } 248 | } 249 | RemoveSpacesOfFilesInDir <- function(patt = "", replace.with = "") { 250 | lf <- list.files(pattern = patt) 251 | new.names <- str_replace_all(lf, " ", replace.with) 252 | file.rename(lf, new.names) 253 | } 254 | RemoveAdjacentSameElements <- function(vec) { 255 | # given a vector, wherever it happens that element i+1 is equal to element i, remove element i+1 and do this recursively until no two adjacent elements are the same (so c(3, 4, 4, 5, 8, 8, 8, 3) becomes c(3, 4, 5, 8, 3)) 256 | l <- length(vec) 257 | vec1 <- vec[1:(l - 1)] 258 | vec2 <- vec[2:l] 259 | to.remove <- which(vec1 == vec2) + 1 260 | vec <- vec[-to.remove] 261 | return(vec) 262 | } 263 | RenameWithNums <- function(file.type, dir = ".") { 264 | init.dir <- getwd() 265 | setwd(dir) 266 | ext <- ifelse(CharVec(file.type)[1] == ".", file.type, paste0(".", file.type)) 267 | lf <- list.files(pattern = ext) 268 | l <- length(lf) 269 | new.names <- paste0(1:l, ext) 270 | if (any(new.names %in% lf)) stop("Some of the names are already in the desired format, unable to proceed as renaming may result in deletion.") 271 | file.rename(lf, new.names) 272 | NiceFileNums(ext) 273 | setwd(init.dir) 274 | } 275 | RIM <- function(file.name, z = 0) { # ReadImageMatrix 276 | # Reads the image matrix in as I like it, i.e. a transposed version of the default. The default reads in the matrix where matrix entry [i, j] refers to the pixel x=1, y=j but for a traditional matrix the idea is the other way around namely [i, j] refers to the entry in row i, column j. This is how I want it to be, because I want to treat it how I treat every other matrix. 277 | image.data <- imageData(suppressWarnings(readImage(file.name))) 278 | dims.initial <- dim(image.data) 279 | if (z == "all" | z == "a") { 280 | stack.as.list <- ImgStack2GrayscaleList(image.data) 281 | transpositions <- lapply(stack.as.list, t) 282 | back.to.stack <- do.call(abind, c(transpositions, along=3)) 283 | return(back.to.stack) 284 | } else if (z) { 285 | return(t(image.data[, , z])) 286 | } else { 287 | return(t(image.data)) 288 | } 289 | } 290 | StrElem <- function(string, element.index) substr(string, element.index, element.index) 291 | StrElemsPasted <- function(string, elem.indices) { 292 | elems <- sapply(elem.indices, StrElem, string = string) 293 | pasted <- paste(elems, collapse = "") 294 | return(pasted) 295 | } 296 | StringsWithPatterns <- function(strings, patterns, ic = f) { 297 | for (p in patterns) strings <- strings[grepl(p, strings, ignore.case = ic)] 298 | return(strings) 299 | } 300 | StringsSepByNums <- function(string) { 301 | # this function doesn't work for strings with decimal numbers 302 | non.numeric.chars <- which(!CanBeNumeric(CharVec(string))) 303 | string.groups <- Grouper(non.numeric.chars) 304 | strings <- sapply(string.groups, StrElemsPasted, string = string) 305 | return(strings) 306 | } 307 | StrReverse <- function(string) { 308 | char.vec <- CharVec(string) 309 | char.vec.reversed <- rev(char.vec) 310 | string.reversed <- paste(char.vec.reversed, collapse = "") 311 | return(string.reversed) 312 | } 313 | T2Cols <- function(df) { 314 | cns <- colnames(df) 315 | last.nums <- sapply(cns, LastNumber) 316 | if (!MyAllEqual(paste0("t", last.nums), cns)) stop("columns must be t numbered (i.e. t1, t2, t3 or something like that)") 317 | no.nas <- sapply(df, na.omit) 318 | ls <- sapply(no.nas, length) 319 | ts <- rep(last.nums, ls) 320 | xs <- Reduce(c, no.nas) 321 | ts.xs <- cbind(ts, xs) 322 | } 323 | Vec2csv <- function(vec, csv.name, vec.name = "x", rn = F) { 324 | # vec: Vector, rn: RowNames 325 | d.f <- data.frame(vec) 326 | colnames(d.f) <- vec.name 327 | ext <- ".csv" 328 | if (RightChars(csv.name, 4) != ext) csv.name <- paste0(csv.name, ext) 329 | write.csv(d.f, csv.name, row.names = rn) 330 | } 331 | 332 | 333 | -------------------------------------------------------------------------------- /junk/PossibleJunk.R: -------------------------------------------------------------------------------- 1 | #' Interleave two vectors. 2 | #' 3 | #' Given two vectors that differ in length by at most 1, interleave them into a 4 | #' vector where every odd element is from the first vector and every even 5 | #' element is from the second. Hence, every second element is from the same 6 | #' original vector and every next element is from a different vector. This is 7 | #' done in the natural order. 8 | #' @param vec1 A vector. If the vectors are of different lengths, this must be 9 | #' the longer one. 10 | #' @param vec2 A vector of either the same length as vec1 or 1 shorter than it. 11 | #' @return A vector which is \code{vec1} and \code{vec2} interleaved. 12 | #' @examples 13 | #' Interleave(c("a", "b", "c"), c("x", "y", "z")) 14 | #' Interleave(c("a", "b", "c", "d"), c("x", "y", "z")) 15 | #' @export 16 | Interleave <- function(vec1, vec2) { 17 | l1 <- length(vec1) 18 | l2 <- length(vec2) 19 | if (l1 < 1 || l2 < 1) stop("Both vectors must have positive lengths.") 20 | if (! (l1 - l2) %in% 0:1) 21 | stop("vec1 must be either the same length as vec2 or one longer than it") 22 | ans <- 1:(l1 + l2) 23 | ans[seq(1, 2 * l1 - 1, 2)] <- vec1 24 | ans[seq(2, 2 * l2, 2)] <- vec2 25 | return(ans) 26 | } 27 | -------------------------------------------------------------------------------- /junk/Strings.R: -------------------------------------------------------------------------------- 1 | AsNumeric <- function(arg) suppressWarnings(as.numeric(arg)) 2 | AfterLast <- function(strings, last) { 3 | # Chops of the leading part of the string up to and including the last instance of the charachter (or series of characters) specified in the last argument 4 | instancess <- gregexpr(last, strings) 5 | last.instances <- sapply(instancess, Last) 6 | chops <- mapply(substr, strings, last.instances + 1, nchar(strings)) 7 | } 8 | AllButFirstNChar <- function(string, n) { 9 | nc <- nchar(string) 10 | if (nc < 2) stop("string must be more than 1 character") 11 | abfn <- substr(string, n + 1, nc) 12 | return(abfn) 13 | } 14 | CharVec <- function(string) strsplit(string, NULL)[[1]] 15 | FirstNumber <- function(string, leave.as.string = F) { 16 | char.vec <- sapply(1:nchar(string), StrElem, string = string) 17 | first.numeric <- match(F, is.na(AsNumeric(char.vec))) 18 | non.numeric.start.gone <- substr(string, first.numeric, nchar(string)) 19 | first.number <- LeadingNumber(non.numeric.start.gone, leave.as.string) 20 | return(first.number) 21 | } 22 | LastNumber <- function(string, leave.as.string = F) { 23 | string.reversed <- StrReverse(string) 24 | last.num.backwards.string <- FirstNumber(string.reversed, leave.as.string = T) 25 | last.num.string <- StrReverse(last.num.backwards.string) 26 | if (leave.as.string) { 27 | return(last.num.string) 28 | } else { 29 | last.num <- as.numeric(last.num.string) 30 | return(last.num) 31 | } 32 | } 33 | Last <- function(listorvec) { 34 | l <- length(listorvec) 35 | if (is.list(listorvec)) { 36 | return(listorvec[[l]]) 37 | } else { 38 | return(listorvec[l]) 39 | } 40 | } 41 | LeadingNumber <- function(string, leave.as.string = F) { 42 | if (!is.na(suppressWarnings(as.numeric(string)))) { 43 | if (leave.as.string) { 44 | return(toString(string)) 45 | } else { 46 | return(as.numeric(string)) 47 | } 48 | } else if (is.na(suppressWarnings(as.numeric(StrElem(string, 1))))) { 49 | stop("string does not begin with a numeric character") 50 | } else { 51 | char.vec <- sapply(1:nchar(string), StrElem, string = string) 52 | suppressWarnings(numeric.or.not <- sapply(char.vec, as.numeric)) 53 | last.numeric <- match(NA, numeric.or.not) - 1 54 | number.as.string <- substr(string, 1, last.numeric) 55 | if (leave.as.string) { 56 | return(number.as.string) 57 | } else { 58 | number <- as.numeric(number.as.string) 59 | return(number) 60 | } 61 | } 62 | } 63 | MyAllEqual <- function(a, b = NA, cn = F) { 64 | if (is.na(b)) { 65 | return(length(unique(a)) == 1) 66 | } else { 67 | return(isTRUE(all.equal(a, b, check.names = cn))) 68 | } 69 | } 70 | Mat2RowList <- function(mat) { 71 | # convert a matrix into a list where each list element is a row of that matrix 72 | RowList <- split(t(mat), rep(1:ncol(t(mat)), each=nrow(t(mat)))) 73 | return(RowList) 74 | } 75 | Mat2ColList <- function(mat) { 76 | # convert a matrix into a list where each list element is a column of that matrix 77 | RowList <- split(mat, rep(1:ncol(mat), each=nrow(mat))) 78 | return(RowList) 79 | } 80 | NumNameFiles <- function() { 81 | lf <- list.files() 82 | extensions <- AfterLast(lf, "\\.") 83 | new.names <- paste0(1:length(extensions), ".", extensions) 84 | if (any(new.names %in% lf)) stop("some o") 85 | file.rename(lf, new.names) 86 | } 87 | OccurrenceNumber <- function(m, vec) { 88 | sum(vec[1:m] == vec[m]) 89 | # element m is which occurrence of that value in the vector vec 90 | # so OccurrenceNumber(4, c(1, 3, 2, 3, 3)) = 2. 91 | } 92 | OccurrenceNumberAll <- function(vec) { 93 | sapply(1:length(vec), OccurrenceNumber, vec) 94 | } 95 | OrderOnAthenB <- function(a, b) { 96 | # a and b should be numeric 97 | l <- length(a) 98 | if (l != length(b)) stop("arguments must be of same length") 99 | if (any(b < 0)) b <- b - min(b) # mak sure a is non-negative 100 | a.diffs <- apply(AllPairs(a), 1, function(x) abs(x[1] - x[2])) # differences between elements of a 101 | min.g0.ad <- min(a.diffs[a.diffs > 0]) # the minimum greated than zero a difference 102 | b.tata <- b * (min.g0.ad / max(b)) / 2 # B_ToAdd_ToA. This is a scaled version of b whose max element will be max(b) * (min.g0.ad / max(b)) / 2 = min.g0.ad / 2 which is less than the minimum greater than zero a difference. This gives that a[i] < a[j] => a[i] + b.tata[i] < a[j] + b.tata[j], so adding b.tata to a preserves order of unequal elements. Also we have b[i] < b[j] => b.tata[i] < b.tata[j]; since b.tata is just a scaled version of b, order is preserved. However for a[i] = a[j], we have b[i] < b[j] => b.tata[i] < b.tata[j] => a[i] + b.tata[i] < a[j] + b.tata[j]. So we have that the addition of b.tata to a preserves the order of unequal elements and orders equal elements according to b, which is what we want to order on a then b (then we just have to take order(a + b.tata)). 103 | to <- a + b.tata # ToOrder 104 | return(order(to)) 105 | } 106 | StrElem <- function(string, element.index) { 107 | elem <- substr(string, element.index, element.index) 108 | return(elem) 109 | } 110 | StringsWithPatterns <- function(strings, patterns, ic = F) { 111 | for (p in patterns) strings <- strings[grepl(p, strings, ignore.case = ic)] 112 | return(strings) 113 | } 114 | StrReverse <- function(string) { 115 | char.vec <- CharVec(string) 116 | char.vec.reversed <- rev(char.vec) 117 | string.reversed <- paste(char.vec.reversed, collapse = "") 118 | return(string.reversed) 119 | } 120 | UpToLast <- function(strings, last) { 121 | # Chops off the last bit of the string which starts with the charachter (or series of characters) specified in the last argument 122 | instancess <- gregexpr(last, strings) 123 | last.instances <- sapply(instancess, Last) 124 | chopped.offs <- mapply(substr, strings, 1, last.instances - 1) 125 | } 126 | -------------------------------------------------------------------------------- /junk/filesstrings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rorynolan/filesstrings/b9e4b5fcbc0edc5cab0fdb028554a1fff113f644/junk/filesstrings.png -------------------------------------------------------------------------------- /junk/filesstrings.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rorynolan/filesstrings/b9e4b5fcbc0edc5cab0fdb028554a1fff113f644/junk/filesstrings.pptx -------------------------------------------------------------------------------- /junk/sticker.R: -------------------------------------------------------------------------------- 1 | pkgs <- c("hexSticker", "tidyverse", "here", "magick") 2 | invisible(lapply(pkgs, library, character.only = TRUE)) 3 | 4 | sticker(here("junk", "filesstrings.png"), package = "filesstrings", 5 | filename = here("junk", "sticker.png"), 6 | s_x = 1, s_y = .75, s_height = 1, 7 | url = "github.com/rorynolan/filesstrings", 8 | p_y = 1.4, p_color = "black", 9 | u_x = 1.13, u_color = "white", u_size = 0.8, 10 | h_color = "black", h_fill = "orange") 11 | image_read(here("junk", "sticker.png")) 12 | -------------------------------------------------------------------------------- /junk/sticker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rorynolan/filesstrings/b9e4b5fcbc0edc5cab0fdb028554a1fff113f644/junk/sticker.png -------------------------------------------------------------------------------- /man/all_equal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/all-equal.R 3 | \name{all_equal} 4 | \alias{all_equal} 5 | \title{An alternative version of \code{\link[base:all.equal]{base::all.equal()}}.} 6 | \usage{ 7 | all_equal(a, b = NULL) 8 | } 9 | \arguments{ 10 | \item{a}{A vector, array or list.} 11 | 12 | \item{b}{Either \code{NULL} or a vector, array or list of length either 1 or 13 | \code{length(a)}.} 14 | } 15 | \value{ 16 | \code{TRUE} if "equality of all" is satisfied (as detailed in 17 | 'Description' above) and \code{FALSE} otherwise. 18 | } 19 | \description{ 20 | This function will return \code{TRUE} whenever \code{\link[base:all.equal]{base::all.equal()}} 21 | would return \code{TRUE}, however it will also return \code{TRUE} in some other cases: 22 | \itemize{ 23 | \item If \code{a} is given and \code{b} is not, \code{TRUE} will be returned if all of the 24 | elements of \code{a} are the same. 25 | \item If \code{a} is a scalar and \code{b} is a vector or array, \code{TRUE} will be returned 26 | if every element in \code{b} is equal to \code{a}. 27 | \item If \code{a} is a vector or array and \code{b} is a scalar, \code{TRUE} will be returned 28 | if every element in \code{a} is equal to \code{b}. 29 | } 30 | 31 | This function ignores names and attributes (except for \code{dim}). 32 | 33 | When this function does not return \code{TRUE}, it returns \code{FALSE} (unless it 34 | errors). This is unlike \code{\link[base:all.equal]{base::all.equal()}}. 35 | } 36 | \note{ 37 | \itemize{\item This behaviour is totally different from 38 | \code{\link[base:all.equal]{base::all.equal()}}. \item There's also \code{\link[dplyr:all_equal]{dplyr::all_equal()}}, which is 39 | different again. To avoid confusion, always use the full 40 | \code{filesstrings::all_equal()} and never \code{library(filesstrings)} followed by 41 | just \code{all_equal()}.} 42 | } 43 | \examples{ 44 | all_equal(1, rep(1, 3)) 45 | all_equal(2, 1:3) 46 | all_equal(1:4, 1:4) 47 | all_equal(1:4, c(1, 2, 3, 3)) 48 | all_equal(rep(1, 10)) 49 | all_equal(c(1, 88)) 50 | all_equal(1:2) 51 | all_equal(list(1:2)) 52 | all_equal(1:4, matrix(1:4, nrow = 2)) # note that this gives TRUE 53 | } 54 | -------------------------------------------------------------------------------- /man/before_last_dot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-before.R 3 | \name{before_last_dot} 4 | \alias{before_last_dot} 5 | \alias{str_before_last_dot} 6 | \title{Get the part of a string before the last period.} 7 | \usage{ 8 | before_last_dot(...) 9 | 10 | str_before_last_dot(...) 11 | } 12 | \arguments{ 13 | \item{...}{Pass-through to \code{strex} function.} 14 | } 15 | \description{ 16 | Copy of \code{\link[strex:str_before_last_dot]{strex::str_before_last_dot()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/can_be_numeric.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/can-be-num.R 3 | \name{can_be_numeric} 4 | \alias{can_be_numeric} 5 | \alias{str_can_be_numeric} 6 | \title{Check if a string could be considered as numeric.} 7 | \usage{ 8 | can_be_numeric(...) 9 | 10 | str_can_be_numeric(...) 11 | } 12 | \arguments{ 13 | \item{...}{Pass-through to \code{strex} function.} 14 | } 15 | \description{ 16 | Copy of \code{\link[strex:str_can_be_numeric]{strex::str_can_be_numeric()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/create_dir.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/files.R 3 | \name{create_dir} 4 | \alias{create_dir} 5 | \title{Create directories if they don't already exist} 6 | \usage{ 7 | create_dir(...) 8 | } 9 | \arguments{ 10 | \item{...}{The names of the directories, specified via relative or absolute 11 | paths. Duplicates are ignored.} 12 | } 13 | \value{ 14 | Invisibly, a vector with a \code{TRUE} for each time a directory was 15 | actually created and a \code{FALSE} otherwise. This vector is named with the 16 | paths of the directories that were passed to the function. 17 | } 18 | \description{ 19 | Given the names of (potential) directories, create the ones that do not 20 | already exist. 21 | } 22 | \examples{ 23 | \dontrun{ 24 | create_dir(c("mydir", "yourdir")) 25 | remove_dir(c("mydir", "yourdir")) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /man/currency.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-currency.R 3 | \name{currency} 4 | \alias{currency} 5 | \alias{str_extract_currencies} 6 | \alias{extract_currencies} 7 | \alias{str_nth_currency} 8 | \alias{nth_currency} 9 | \alias{str_first_currency} 10 | \alias{first_currency} 11 | \alias{str_last_currency} 12 | \alias{last_currency} 13 | \title{Get the currencies of numbers within a string.} 14 | \usage{ 15 | str_extract_currencies(...) 16 | 17 | extract_currencies(...) 18 | 19 | str_nth_currency(...) 20 | 21 | nth_currency(...) 22 | 23 | str_first_currency(...) 24 | 25 | first_currency(...) 26 | 27 | str_last_currency(...) 28 | 29 | last_currency(...) 30 | } 31 | \arguments{ 32 | \item{...}{Pass-through to \code{strex} function.} 33 | } 34 | \description{ 35 | See \code{\link[strex:currency]{strex::str_extract_currencies()}}. 36 | } 37 | -------------------------------------------------------------------------------- /man/extend_char_vec.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-pad.R 3 | \name{extend_char_vec} 4 | \alias{extend_char_vec} 5 | \alias{str_extend_char_vec} 6 | \title{Pad a character vector with empty strings.} 7 | \usage{ 8 | extend_char_vec(char_vec, extend_by = NA, length_out = NA) 9 | 10 | str_extend_char_vec(char_vec, extend_by = NA, length_out = NA) 11 | } 12 | \arguments{ 13 | \item{char_vec}{A character vector. The thing you wish to expand.} 14 | 15 | \item{extend_by}{A non-negative integer. By how much do you wish to extend 16 | the vector?} 17 | 18 | \item{length_out}{A positive integer. How long do you want the output vector 19 | to be?} 20 | } 21 | \value{ 22 | A character vector. 23 | } 24 | \description{ 25 | Extend a character vector by appending empty strings at the end. 26 | } 27 | \examples{ 28 | extend_char_vec(1:5, extend_by = 2) 29 | extend_char_vec(c("a", "b"), length_out = 10) 30 | } 31 | -------------------------------------------------------------------------------- /man/extract_non_numerics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-extract-non-nums.R 3 | \name{extract_non_numerics} 4 | \alias{extract_non_numerics} 5 | \alias{str_extract_non_numerics} 6 | \alias{nth_non_numeric} 7 | \alias{str_nth_non_numeric} 8 | \alias{first_non_numeric} 9 | \alias{str_first_non_numeric} 10 | \alias{last_non_numeric} 11 | \alias{str_last_non_numeric} 12 | \title{Extract non-numbers from a string.} 13 | \usage{ 14 | extract_non_numerics(...) 15 | 16 | str_extract_non_numerics(...) 17 | 18 | nth_non_numeric(...) 19 | 20 | str_nth_non_numeric(...) 21 | 22 | first_non_numeric(...) 23 | 24 | str_first_non_numeric(...) 25 | 26 | last_non_numeric(...) 27 | 28 | str_last_non_numeric(...) 29 | } 30 | \arguments{ 31 | \item{...}{Pass-through to \code{strex} function.} 32 | } 33 | \description{ 34 | Copies of \code{\link[strex:str_extract_non_numerics]{strex::str_extract_non_numerics()}} and friends. 35 | } 36 | -------------------------------------------------------------------------------- /man/extract_numbers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-extract-nums.R 3 | \name{extract_numbers} 4 | \alias{extract_numbers} 5 | \alias{str_extract_numbers} 6 | \alias{nth_number} 7 | \alias{str_nth_number} 8 | \alias{first_number} 9 | \alias{str_first_number} 10 | \alias{last_number} 11 | \alias{str_last_number} 12 | \title{Extract numbers from a string.} 13 | \usage{ 14 | extract_numbers(...) 15 | 16 | str_extract_numbers(...) 17 | 18 | nth_number(...) 19 | 20 | str_nth_number(...) 21 | 22 | first_number(...) 23 | 24 | str_first_number(...) 25 | 26 | last_number(...) 27 | 28 | str_last_number(...) 29 | } 30 | \arguments{ 31 | \item{...}{Pass-through to \code{strex} function.} 32 | } 33 | \description{ 34 | Copies of \code{\link[strex:str_extract_numbers]{strex::str_extract_numbers()}} and friends. 35 | } 36 | -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rorynolan/filesstrings/b9e4b5fcbc0edc5cab0fdb028554a1fff113f644/man/figures/logo.png -------------------------------------------------------------------------------- /man/filesstrings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/filesstrings-package.R 3 | \docType{package} 4 | \name{filesstrings} 5 | \alias{filesstrings} 6 | \alias{filesstrings-package} 7 | \title{\code{filesstrings}: handy file and string manipulation} 8 | \description{ 9 | This started out as a package for file and string manipulation. Since then, 10 | the \code{fs} file manipulation package and the \code{strex} string manipulation 11 | package emerged, offering functionality previously given by this package (but 12 | slightly better). Those packages have hence almost pushed 'filesstrings' into 13 | extinction. However, it still has a small number of unique, handy file 14 | manipulation functions which can be seen in the \href{https://cran.r-project.org/package=filesstrings/vignettes/files.html}{vignette}.. 15 | One example is a function to remove spaces from all file names in a 16 | directory. 17 | } 18 | \references{ 19 | Rory Nolan and Sergi Padilla-Parra (2017). filesstrings: An R 20 | package for file and string manipulation. The Journal of Open Source 21 | Software, 2(14). \doi{10.21105/joss.00260}. 22 | } 23 | -------------------------------------------------------------------------------- /man/group_close.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{group_close} 4 | \alias{group_close} 5 | \title{Group together close adjacent elements of a vector.} 6 | \usage{ 7 | group_close(vec_ascending, max_gap = 1) 8 | } 9 | \arguments{ 10 | \item{vec_ascending}{A strictly increasing numeric vector.} 11 | 12 | \item{max_gap}{The biggest allowable gap between adjacent elements for them 13 | to be considered part of the same \emph{group}.} 14 | } 15 | \value{ 16 | A where each element is one group, as a numeric vector. 17 | } 18 | \description{ 19 | Given a strictly increasing vector (each element is bigger than the last), 20 | group together stretches of the vector where \emph{adjacent} elements are 21 | separated by at most some specified distance. Hence, each element in each 22 | group has at least one other element in that group that is \emph{close} to 23 | it. See the examples. 24 | } 25 | \examples{ 26 | group_close(1:10, 1) 27 | group_close(1:10, 0.5) 28 | group_close(c(1, 2, 4, 10, 11, 14, 20, 25, 27), 3) 29 | } 30 | -------------------------------------------------------------------------------- /man/locate_braces.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-locate.R 3 | \name{locate_braces} 4 | \alias{locate_braces} 5 | \alias{str_locate_braces} 6 | \title{Locate the braces in a string.} 7 | \usage{ 8 | locate_braces(...) 9 | 10 | str_locate_braces(...) 11 | } 12 | \arguments{ 13 | \item{...}{Pass-through to \code{strex} function.} 14 | } 15 | \description{ 16 | Copy of \code{\link[strex:str_locate_braces]{strex::str_locate_braces()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/match_arg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/arg-match.R 3 | \name{match_arg} 4 | \alias{match_arg} 5 | \alias{str_match_arg} 6 | \title{Argument Matching} 7 | \usage{ 8 | match_arg(...) 9 | 10 | str_match_arg(...) 11 | } 12 | \arguments{ 13 | \item{...}{Pass-through to \code{strex} function.} 14 | } 15 | \description{ 16 | Copy of \code{\link[strex:str_match_arg]{strex::match_arg()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/move_files.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/files.R 3 | \name{move_files} 4 | \alias{move_files} 5 | \alias{file.move} 6 | \title{Move files around.} 7 | \usage{ 8 | move_files(files, destinations, overwrite = FALSE) 9 | 10 | file.move(files, destinations, overwrite = FALSE) 11 | } 12 | \arguments{ 13 | \item{files}{A character vector of files to move (relative or absolute 14 | paths).} 15 | 16 | \item{destinations}{A character vector of the destination directories into 17 | which to move the files.} 18 | 19 | \item{overwrite}{Allow overwriting of files? Default no.} 20 | } 21 | \value{ 22 | Invisibly, a logical vector with a \code{TRUE} for each time the operation 23 | succeeded and a \code{FALSE} for every fail. 24 | } 25 | \description{ 26 | Move specified files into specified directories 27 | } 28 | \details{ 29 | If there are \eqn{n} files, there must be either \eqn{1} or \eqn{n} 30 | directories. If there is one directory, then all \eqn{n} files are moved 31 | there. If there are \eqn{n} directories, then each file is put into its 32 | respective directory. This function also works to move directories. 33 | 34 | If you try to move files to a directory that doesn't exist, the directory is 35 | first created and then the files are put inside. 36 | } 37 | \examples{ 38 | \dontrun{ 39 | dir.create("dir") 40 | files <- c("1litres_1.txt", "1litres_30.txt", "3litres_5.txt") 41 | file.create(files) 42 | file.move(files, "dir") 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /man/nice_file_nums.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/files.R 3 | \name{nice_file_nums} 4 | \alias{nice_file_nums} 5 | \title{Make file numbers comply with alphabetical order} 6 | \usage{ 7 | nice_file_nums(dir = ".", pattern = NA) 8 | } 9 | \arguments{ 10 | \item{dir}{Path (relative or absolute) to the directory in which to do the 11 | renaming (default is current working directory).} 12 | 13 | \item{pattern}{A regular expression. If specified, files to be renamed are 14 | restricted to ones matching this pattern (in their name).} 15 | } 16 | \value{ 17 | A logical vector with a \code{TRUE} for each successful rename 18 | (should be all \code{TRUE}s) and a \code{FALSE} otherwise. 19 | } 20 | \description{ 21 | If files are numbered, their numbers may not \emph{comply} with alphabetical 22 | order, i.e. "file2.ext" comes after "file10.ext" in alphabetical order. This 23 | function renames the files in the specified directory such that they comply 24 | with alphabetical order, so here "file2.ext" would be renamed to 25 | "file02.ext". 26 | } 27 | \details{ 28 | It works on file names with more than one number in them e.g. 29 | "file01part3.ext" (a file with 2 numbers). All the file names that it works 30 | on must have the same number of numbers, and the non-number bits must be the 31 | same. One can limit the renaming to files matching a certain pattern. This 32 | function wraps \code{\link[=nice_nums]{nice_nums()}}, which does the string operations, but 33 | not the renaming. To see examples of how this function works, see the 34 | examples in that function's documentation. 35 | } 36 | \examples{ 37 | \dontrun{ 38 | dir.create("NiceFileNums_test") 39 | setwd("NiceFileNums_test") 40 | files <- c("1litres_1.txt", "1litres_30.txt", "3litres_5.txt") 41 | file.create(files) 42 | nice_file_nums() 43 | nice_file_nums(pattern = "\\\\.txt$") 44 | setwd("..") 45 | dir.remove("NiceFileNums_test") 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /man/nth_number_after_mth.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-num-after.R 3 | \name{nth_number_after_mth} 4 | \alias{nth_number_after_mth} 5 | \alias{str_nth_number_after_mth} 6 | \alias{nth_number_after_first} 7 | \alias{nth_number_after_last} 8 | \alias{first_number_after_mth} 9 | \alias{last_number_after_mth} 10 | \alias{first_number_after_first} 11 | \alias{first_number_after_last} 12 | \alias{last_number_after_first} 13 | \alias{last_number_after_last} 14 | \alias{str_nth_number_after_first} 15 | \alias{str_nth_number_after_last} 16 | \alias{str_first_number_after_mth} 17 | \alias{str_last_number_after_mth} 18 | \alias{str_first_number_after_first} 19 | \alias{str_first_number_after_last} 20 | \alias{str_last_number_after_first} 21 | \alias{str_last_number_after_last} 22 | \title{Find the \code{n}th number after the \code{m}th occurrence of a pattern.} 23 | \usage{ 24 | nth_number_after_mth(...) 25 | 26 | str_nth_number_after_mth(...) 27 | 28 | nth_number_after_first(...) 29 | 30 | nth_number_after_last(...) 31 | 32 | first_number_after_mth(...) 33 | 34 | last_number_after_mth(...) 35 | 36 | first_number_after_first(...) 37 | 38 | first_number_after_last(...) 39 | 40 | last_number_after_first(...) 41 | 42 | last_number_after_last(...) 43 | 44 | str_nth_number_after_first(...) 45 | 46 | str_nth_number_after_last(...) 47 | 48 | str_first_number_after_mth(...) 49 | 50 | str_last_number_after_mth(...) 51 | 52 | str_first_number_after_first(...) 53 | 54 | str_first_number_after_last(...) 55 | 56 | str_last_number_after_first(...) 57 | 58 | str_last_number_after_last(...) 59 | } 60 | \arguments{ 61 | \item{...}{Pass-through to \code{strex} function.} 62 | } 63 | \description{ 64 | Copy of \code{\link[strex:str_nth_number_after_mth]{strex::str_nth_number_after_mth()}}. 65 | } 66 | -------------------------------------------------------------------------------- /man/nth_number_before_mth.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-num-before.R 3 | \name{nth_number_before_mth} 4 | \alias{nth_number_before_mth} 5 | \alias{str_nth_number_before_mth} 6 | \alias{nth_number_before_first} 7 | \alias{nth_number_before_last} 8 | \alias{first_number_before_mth} 9 | \alias{last_number_before_mth} 10 | \alias{first_number_before_first} 11 | \alias{first_number_before_last} 12 | \alias{last_number_before_first} 13 | \alias{last_number_before_last} 14 | \alias{str_nth_number_before_first} 15 | \alias{str_nth_number_before_last} 16 | \alias{str_first_number_before_mth} 17 | \alias{str_last_number_before_mth} 18 | \alias{str_first_number_before_first} 19 | \alias{str_first_number_before_last} 20 | \alias{str_last_number_before_first} 21 | \alias{str_last_number_before_last} 22 | \title{Find the \code{n}th number before the \code{m}th occurrence of a pattern.} 23 | \usage{ 24 | nth_number_before_mth(...) 25 | 26 | str_nth_number_before_mth(...) 27 | 28 | nth_number_before_first(...) 29 | 30 | nth_number_before_last(...) 31 | 32 | first_number_before_mth(...) 33 | 34 | last_number_before_mth(...) 35 | 36 | first_number_before_first(...) 37 | 38 | first_number_before_last(...) 39 | 40 | last_number_before_first(...) 41 | 42 | last_number_before_last(...) 43 | 44 | str_nth_number_before_first(...) 45 | 46 | str_nth_number_before_last(...) 47 | 48 | str_first_number_before_mth(...) 49 | 50 | str_last_number_before_mth(...) 51 | 52 | str_first_number_before_first(...) 53 | 54 | str_first_number_before_last(...) 55 | 56 | str_last_number_before_first(...) 57 | 58 | str_last_number_before_last(...) 59 | } 60 | \arguments{ 61 | \item{...}{Pass-through to \code{strex} function.} 62 | } 63 | \description{ 64 | Copy of \code{\link[strex:str_nth_number_before_mth]{strex::str_nth_number_before_mth()}}. 65 | } 66 | -------------------------------------------------------------------------------- /man/put_in_pos.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-put-in-pos.R 3 | \name{put_in_pos} 4 | \alias{put_in_pos} 5 | \alias{str_put_in_pos} 6 | \title{Put specified strings in specified positions in an otherwise empty character 7 | vector.} 8 | \usage{ 9 | put_in_pos(strings, positions) 10 | 11 | str_put_in_pos(strings, positions) 12 | } 13 | \arguments{ 14 | \item{strings}{A character vector of the strings to put in positions 15 | (coerced by \link{as.character} if not character already).} 16 | 17 | \item{positions}{The indices of the character vector to be occupied by the 18 | elements of strings. Must be the same length as strings or of length 1.} 19 | } 20 | \value{ 21 | A character vector. 22 | } 23 | \description{ 24 | Create a character vector with a set of strings at specified positions in 25 | that character vector, with the rest of it taken up by empty strings. 26 | } 27 | \examples{ 28 | put_in_pos(1:3, c(1, 8, 9)) 29 | put_in_pos(c("Apple", "Orange", "County"), c(5, 7, 8)) 30 | put_in_pos(1:2, 5) 31 | } 32 | -------------------------------------------------------------------------------- /man/remove_dir.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/files.R 3 | \name{remove_dir} 4 | \alias{remove_dir} 5 | \alias{dir.remove} 6 | \title{Remove directories} 7 | \usage{ 8 | remove_dir(...) 9 | 10 | dir.remove(...) 11 | } 12 | \arguments{ 13 | \item{...}{The names of the directories, specified via relative or absolute 14 | paths.} 15 | } 16 | \value{ 17 | Invisibly, a logical vector with \code{TRUE} for each success and 18 | \code{FALSE} for failures. 19 | } 20 | \description{ 21 | Delete directories and all of their contents. 22 | } 23 | \examples{ 24 | \dontrun{ 25 | sapply(c("mydir1", "mydir2"), dir.create) 26 | remove_dir(c("mydir1", "mydir2")) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /man/remove_filename_spaces.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/files.R 3 | \name{remove_filename_spaces} 4 | \alias{remove_filename_spaces} 5 | \title{Remove spaces in file names} 6 | \usage{ 7 | remove_filename_spaces(dir = ".", pattern = "", replacement = "") 8 | } 9 | \arguments{ 10 | \item{dir}{The directory in which to perform the operation.} 11 | 12 | \item{pattern}{A regular expression. If specified, only files matching this 13 | pattern will be treated.} 14 | 15 | \item{replacement}{What do you want to replace the spaces with? This 16 | defaults to nothing, another sensible choice would be an underscore.} 17 | } 18 | \value{ 19 | A logical vector indicating which operation succeeded for each of the 20 | files attempted. Using a missing value for a file or path name will always 21 | be regarded as a failure. 22 | } 23 | \description{ 24 | Remove spaces in file names in a specified directory, replacing them with 25 | whatever you want, default nothing. 26 | } 27 | \examples{ 28 | \dontrun{ 29 | dir.create("RemoveFileNameSpaces_test") 30 | setwd("RemoveFileNameSpaces_test") 31 | files <- c("1litres 1.txt", "1litres 30.txt", "3litres 5.txt") 32 | file.create(files) 33 | remove_filename_spaces() 34 | list.files() 35 | setwd("..") 36 | dir.remove("RemoveFileNameSpaces_test") 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /man/rename_with_nums.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/files.R 3 | \name{rename_with_nums} 4 | \alias{rename_with_nums} 5 | \title{Replace file names with numbers} 6 | \usage{ 7 | rename_with_nums(dir = ".", pattern = NULL) 8 | } 9 | \arguments{ 10 | \item{dir}{The directory in which to rename the files (relative or absolute 11 | path). Defaults to current working directory.} 12 | 13 | \item{pattern}{A regular expression. If specified, only files with names 14 | matching this pattern will be treated.} 15 | } 16 | \value{ 17 | A logical vector with a \code{TRUE} for each successful renaming and a 18 | \code{FALSE} otherwise. 19 | } 20 | \description{ 21 | Rename the files in the directory, replacing file names with numbers only. 22 | } 23 | \examples{ 24 | \dontrun{ 25 | dir.create("RenameWithNums_test") 26 | setwd("RenameWithNums_test") 27 | files <- c("1litres 1.txt", "1litres 30.txt", "3litres 5.txt") 28 | file.create(files) 29 | rename_with_nums() 30 | list.files() 31 | setwd("..") 32 | dir.remove("RenameWithNums_test") 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /man/str_after_nth.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-after.R 3 | \name{str_after_nth} 4 | \alias{str_after_nth} 5 | \alias{after_nth} 6 | \alias{str_after_first} 7 | \alias{after_first} 8 | \alias{str_after_last} 9 | \alias{after_last} 10 | \title{Text after the \code{n}th occurrence of pattern.} 11 | \usage{ 12 | str_after_nth(...) 13 | 14 | after_nth(...) 15 | 16 | str_after_first(...) 17 | 18 | after_first(...) 19 | 20 | str_after_last(...) 21 | 22 | after_last(...) 23 | } 24 | \arguments{ 25 | \item{...}{Pass-through to \code{strex} function.} 26 | } 27 | \description{ 28 | Copies of \code{\link[strex:before-and-after]{strex::str_after_nth()}} and friends. 29 | } 30 | -------------------------------------------------------------------------------- /man/str_before_nth.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-before.R 3 | \name{str_before_nth} 4 | \alias{str_before_nth} 5 | \alias{before_nth} 6 | \alias{str_before_first} 7 | \alias{before_first} 8 | \alias{str_before_last} 9 | \alias{before_last} 10 | \title{Text before the \code{n}th occurrence of pattern.} 11 | \usage{ 12 | str_before_nth(...) 13 | 14 | before_nth(...) 15 | 16 | str_before_first(...) 17 | 18 | before_first(...) 19 | 20 | str_before_last(...) 21 | 22 | before_last(...) 23 | } 24 | \arguments{ 25 | \item{...}{Pass-through to \code{strex} function.} 26 | } 27 | \description{ 28 | Copies of \code{\link[strex:before-and-after]{strex::str_before_nth()}} and friends. 29 | } 30 | -------------------------------------------------------------------------------- /man/str_elem.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-elem.R 3 | \name{str_elem} 4 | \alias{str_elem} 5 | \alias{elem} 6 | \title{Extract a single character from a string, using its index.} 7 | \usage{ 8 | str_elem(...) 9 | 10 | elem(...) 11 | } 12 | \arguments{ 13 | \item{...}{Pass-through to \code{strex} function.} 14 | } 15 | \description{ 16 | Copy of \code{\link[strex:str_elem]{strex::str_elem()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/str_elems.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-elem.R 3 | \name{str_elems} 4 | \alias{str_elems} 5 | \alias{elems} 6 | \title{Extract several single elements from a string.} 7 | \usage{ 8 | str_elems(...) 9 | 10 | elems(...) 11 | } 12 | \arguments{ 13 | \item{...}{Pass-through to \code{strex} function.} 14 | } 15 | \description{ 16 | Copy of \code{\link[strex:str_elems]{strex::str_elems()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/str_give_ext.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-give-ext.R 3 | \name{str_give_ext} 4 | \alias{str_give_ext} 5 | \alias{give_ext} 6 | \title{Ensure a file name has the intended extension.} 7 | \usage{ 8 | str_give_ext(...) 9 | 10 | give_ext(...) 11 | } 12 | \arguments{ 13 | \item{...}{Pass-through to \code{strex} function.} 14 | } 15 | \description{ 16 | Copy of \code{\link[strex:str_give_ext]{strex::str_give_ext()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/str_locate_nth.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-locate.R 3 | \name{str_locate_nth} 4 | \alias{str_locate_nth} 5 | \alias{locate_nth} 6 | \alias{str_locate_first} 7 | \alias{locate_first} 8 | \alias{str_locate_last} 9 | \alias{locate_last} 10 | \title{Get the indices of the \eqn{n}th instance of a pattern.} 11 | \usage{ 12 | str_locate_nth(...) 13 | 14 | locate_nth(...) 15 | 16 | str_locate_first(...) 17 | 18 | locate_first(...) 19 | 20 | str_locate_last(...) 21 | 22 | locate_last(...) 23 | } 24 | \arguments{ 25 | \item{...}{Pass-through to \code{strex} function.} 26 | } 27 | \description{ 28 | Copy of \code{\link[strex:str_locate_nth]{strex::str_locate_nth()}}. 29 | } 30 | -------------------------------------------------------------------------------- /man/str_nice_nums.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-nice-nums.R 3 | \name{str_nice_nums} 4 | \alias{str_nice_nums} 5 | \alias{nice_nums} 6 | \alias{str_alphord_nums} 7 | \alias{alphord_nums} 8 | \title{Make string numbers comply with alphabetical order.} 9 | \usage{ 10 | str_nice_nums(...) 11 | 12 | nice_nums(...) 13 | 14 | str_alphord_nums(...) 15 | 16 | alphord_nums(...) 17 | } 18 | \arguments{ 19 | \item{...}{Pass-through to \code{strex} function.} 20 | } 21 | \description{ 22 | Copy of \code{\link[strex:str_alphord_nums]{strex::str_alphord_nums()}}. 23 | } 24 | -------------------------------------------------------------------------------- /man/str_paste_elems.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-elem.R 3 | \name{str_paste_elems} 4 | \alias{str_paste_elems} 5 | \alias{paste_elems} 6 | \title{Extract bits of a string and paste them together.} 7 | \usage{ 8 | str_paste_elems(...) 9 | 10 | paste_elems(...) 11 | } 12 | \arguments{ 13 | \item{...}{Pass-through to \code{strex} function.} 14 | } 15 | \description{ 16 | Copy of \code{\link[strex:str_paste_elems]{strex::str_paste_elems()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/str_remove_quoted.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-remove.R 3 | \name{str_remove_quoted} 4 | \alias{str_remove_quoted} 5 | \alias{remove_quoted} 6 | \title{Remove the quoted parts of a string.} 7 | \usage{ 8 | str_remove_quoted(...) 9 | 10 | remove_quoted(...) 11 | } 12 | \arguments{ 13 | \item{...}{Pass-through to \code{strex} function.} 14 | } 15 | \description{ 16 | Copy of \code{\link[strex:str_remove_quoted]{strex::str_remove_quoted()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/str_singleize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-singleize.R 3 | \name{str_singleize} 4 | \alias{str_singleize} 5 | \alias{singleize} 6 | \title{Remove back-to-back duplicates of a pattern in a string.} 7 | \usage{ 8 | str_singleize(...) 9 | 10 | singleize(...) 11 | } 12 | \arguments{ 13 | \item{...}{Pass-through to \code{strex} function.} 14 | } 15 | \description{ 16 | Copy of \code{\link[strex:str_singleize]{strex::str_singleize()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/str_split_by_nums.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-split-by-nums.R 3 | \name{str_split_by_nums} 4 | \alias{str_split_by_nums} 5 | \alias{split_by_nums} 6 | \alias{split_by_numbers} 7 | \alias{str_split_by_numbers} 8 | \title{Split a string by its numeric characters.} 9 | \usage{ 10 | str_split_by_nums(...) 11 | 12 | split_by_nums(...) 13 | 14 | split_by_numbers(...) 15 | 16 | str_split_by_numbers(...) 17 | } 18 | \arguments{ 19 | \item{...}{Pass-through to \code{strex} function.} 20 | } 21 | \description{ 22 | Copy of \code{\link[strex:str_split_by_numbers]{strex::str_split_by_numbers()}}. 23 | } 24 | -------------------------------------------------------------------------------- /man/str_split_camel_case.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-split.R 3 | \name{str_split_camel_case} 4 | \alias{str_split_camel_case} 5 | \alias{split_camel_case} 6 | \title{Split a string based on CamelCase} 7 | \usage{ 8 | str_split_camel_case(string, lower = FALSE) 9 | 10 | split_camel_case(string, lower = FALSE) 11 | } 12 | \arguments{ 13 | \item{string}{A character vector.} 14 | 15 | \item{lower}{Do you want the output to be all lower case (or as is)?} 16 | } 17 | \description{ 18 | See \code{\link[strex:str_split_camel_case]{strex::str_split_camel_case()}}. 19 | } 20 | -------------------------------------------------------------------------------- /man/str_to_vec.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-to-vec.R 3 | \name{str_to_vec} 4 | \alias{str_to_vec} 5 | \alias{to_vec} 6 | \title{Convert a string to a vector of characters} 7 | \usage{ 8 | str_to_vec(...) 9 | 10 | to_vec(...) 11 | } 12 | \arguments{ 13 | \item{...}{Pass-through to \code{strex} function.} 14 | } 15 | \description{ 16 | Copy of \code{\link[strex:str_to_vec]{strex::str_to_vec()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/str_trim_anything.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/str-trim.R 3 | \name{str_trim_anything} 4 | \alias{str_trim_anything} 5 | \alias{trim_anything} 6 | \title{Trim something other than whitespace.} 7 | \usage{ 8 | str_trim_anything(...) 9 | 10 | trim_anything(...) 11 | } 12 | \arguments{ 13 | \item{...}{Pass-through to \code{strex} function.} 14 | } 15 | \description{ 16 | Copy of \code{\link[strex:str_trim_anything]{strex::str_trim_anything()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/unitize_dirs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/files.R 3 | \name{unitize_dirs} 4 | \alias{unitize_dirs} 5 | \title{Put files with the same unit measurements into directories} 6 | \usage{ 7 | unitize_dirs(unit, pattern = NULL, dir = ".") 8 | } 9 | \arguments{ 10 | \item{unit}{The unit upon which to base the categorizing.} 11 | 12 | \item{pattern}{If set, only files with names matching this pattern will be 13 | treated.} 14 | 15 | \item{dir}{In which directory do you want to perform this action (defaults to 16 | current)?} 17 | } 18 | \value{ 19 | Invisibly \code{TRUE} if the operation is successful, if not there will be 20 | an error. 21 | } 22 | \description{ 23 | Say you have a number of files with "5min" in their names, number with 24 | "10min" in the names, a number with "15min" in their names and so on, and 25 | you'd like to put them into directories named "5min", "10min", "15min" and so 26 | on. This function does this, but not just for the unit "min", for any unit. 27 | } 28 | \details{ 29 | This function takes the number to be the last number (as defined in 30 | \code{\link[=nth_number]{nth_number()}}) before the first occurrence of the unit name. There is the 31 | option to only treat files matching a certain pattern. 32 | } 33 | \examples{ 34 | \dontrun{ 35 | dir.create("UnitDirs_test") 36 | setwd("UnitDirs_test") 37 | files <- c("1litres_1.txt", "1litres_3.txt", "3litres.txt", "5litres_1.txt") 38 | file.create(files) 39 | unitize_dirs("litres", "\\\\.txt") 40 | setwd("..") 41 | dir.remove("UnitDirs_test") 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /paper/codemeta.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": "https://raw.githubusercontent.com/codemeta/codemeta/master/codemeta.jsonld", 3 | "@type": "Code", 4 | "author": [ 5 | { 6 | "@id": "http://orcid.org/0000-0002-5239-4043", 7 | "@type": "Person", 8 | "email": "rorynoolan@gmail.com", 9 | "name": "Rory Nolan", 10 | "affiliation": "University of Oxford" 11 | }, 12 | { 13 | "@id": "http://0000-0002-8010-9481", 14 | "@type": "Person", 15 | "email": "spadilla@well.ox.ac.uk", 16 | "name": "Sergi Padilla", 17 | "affiliation": "University of Oxford" 18 | } 19 | ], 20 | "identifier": "", 21 | "codeRepository": "https://github.com/rorynolan/filesstrings", 22 | "datePublished": "2017-04-11", 23 | "dateModified": "2017-04-11", 24 | "dateCreated": "2017-04-11", 25 | "description": "An R package for file and string manipulation", 26 | "keywords": "R, file, string", 27 | "license": "GPL v3.0", 28 | "title": "filesstrings", 29 | "version": "0.3.2" 30 | } 31 | -------------------------------------------------------------------------------- /paper/paper.bib: -------------------------------------------------------------------------------- 1 | @Manual{R, 2 | title = {R: A Language and Environment for Statistical Computing}, 3 | author = {{R Core Team}}, 4 | organization = {R Foundation for Statistical Computing}, 5 | address = {Vienna, Austria}, 6 | year = {2017}, 7 | url = {https://www.R-project.org/}, 8 | } 9 | @Manual{RStudio, 10 | title = {RStudio: Integrated Development Environment for R}, 11 | author = {{RStudio Team}}, 12 | organization = {RStudio, Inc.}, 13 | address = {Boston, MA}, 14 | year = {2016}, 15 | url = {http://www.rstudio.com/}, 16 | } 17 | @Manual{readr, 18 | title = {readr: Read Rectangular Text Data}, 19 | author = {Hadley Wickham and Jim Hester and Romain Francois}, 20 | year = {2017}, 21 | note = {R package version 1.1.0}, 22 | url = {https://CRAN.R-project.org/package=readr}, 23 | } 24 | @Manual{tibble, 25 | title = {tibble: Simple Data Frames}, 26 | author = {Hadley Wickham and Romain Francois and Kirill Müller}, 27 | year = {2017}, 28 | note = {R package version 1.3.0}, 29 | url = {https://CRAN.R-project.org/package=tibble}, 30 | } 31 | @article{Rcpp, 32 | author = {Dirk Eddelbuettel and Romain Francois}, 33 | title = {Rcpp: Seamless R and C++ Integration}, 34 | journal = {Journal of Statistical Software}, 35 | volume = {40}, 36 | number = {1}, 37 | year = {2011}, 38 | keywords = {}, 39 | abstract = {The Rcpp package simplifies integrating C++ code with R. It provides a consistent C++ class hierarchy that maps various types of R objects (vectors, matrices, functions, environments, . . . ) to dedicated C++ classes. Object interchange between R and C++ is managed by simple, flexible and extensible concepts which include broad support for C++ Standard Template Library idioms. C++ code can both be compiled, linked and loaded on the fly, or added via packages. Flexible error and exception code handling is provided. Rcpp substantially lowers the barrier for programmers wanting to combine C++ code with R.}, 40 | issn = {1548-7660}, 41 | pages = {1--18}, 42 | doi = {10.18637/jss.v040.i08}, 43 | url = {https://www.jstatsoft.org/index.php/jss/article/view/v040i08} 44 | } 45 | @Manual{magrittr, 46 | title = {magrittr: A Forward-Pipe Operator for R}, 47 | author = {Stefan Milton Bache and Hadley Wickham}, 48 | year = {2014}, 49 | note = {R package version 1.5}, 50 | url = {https://CRAN.R-project.org/package=magrittr}, 51 | } 52 | @Manual{ore, 53 | title = {ore: An R Interface to the Oniguruma Regular Expression Library}, 54 | author = {Jon Clayden and based on Onigmo by K. Kosako and K. Takata}, 55 | year = {2016}, 56 | note = {R package version 1.5.0}, 57 | url = {https://CRAN.R-project.org/package=ore}, 58 | } 59 | @Manual{dplyr, 60 | title = {dplyr: A Grammar of Data Manipulation}, 61 | author = {Hadley Wickham and Romain Francois}, 62 | year = {2016}, 63 | note = {R package version 0.5.0}, 64 | url = {https://CRAN.R-project.org/package=dplyr}, 65 | } 66 | @Manual{matrixStats, 67 | title = {matrixStats: Functions that Apply to Rows and Columns of Matrices (and to Vectors)}, 68 | author = {Henrik Bengtsson}, 69 | year = {2017}, 70 | note = {R package version 0.52.1}, 71 | url = {https://CRAN.R-project.org/package=matrixStats}, 72 | } 73 | @Manual{stringr, 74 | title = {stringr: Simple, Consistent Wrappers for Common String Operations}, 75 | author = {Hadley Wickham}, 76 | year = {2017}, 77 | note = {R package version 1.2.0}, 78 | url = {https://CRAN.R-project.org/package=stringr}, 79 | } 80 | @Manual{stringi, 81 | title = {R package stringi: Character string processing facilities}, 82 | author = {Marek Gagolewski and Bartek Tartanus}, 83 | year = {2016}, 84 | url = {http://www.gagolewski.com/software/stringi/}, 85 | } 86 | -------------------------------------------------------------------------------- /paper/paper.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'filesstrings: An R package for file and string manipulation' 3 | tags: 4 | - R 5 | - file 6 | - string 7 | authors: 8 | - name: Rory Nolan 9 | orcid: 0000-0002-5239-4043 10 | affiliation: 1 11 | - name: Sergi Padilla-Parra 12 | orcid: 0000-0002-8010-9481 13 | affiliation: 1, 2 14 | affiliations: 15 | - name: Wellcome Trust Centre for Human Genetics, University of Oxford 16 | index: 1 17 | - name: Department of Structural Biology, University of Oxford 18 | index: 2 19 | date: 11 April 2017 20 | bibliography: paper.bib 21 | nocite: | 22 | @R, @RStudio, @readr, @tibble, @Rcpp, @magrittr, @ore, @dplyr, @matrixStats, @stringr, @stringi 23 | --- 24 | 25 | # Summary 26 | `filesstrings` is an R package providing convenient functions for moving files, deleting directories, and a variety of string operations that facilitate manipulating file names and extracting information from strings. For example, R has no `file.move()`, just `file.copy()` and `file.rename()`, so the best way to move a file was to unintuitively rename it. `filesstrings` provides `file.move()`. The package's string operations mostly pertain to dealing with numbers contained within strings. It has a function `NiceFileNums()` for fixing file names such that their numbering is consistent with alphabetical order. For example, 'file10.txt' comes before 'file9.txt' in alphabetical order, so `NiceFileNums()` recognises this and renames them to 'file10.txt' and 'file09.txt' respectively. See documentation at https://cran.r-project.org/package=filesstrings. 27 | 28 | # References 29 | -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | if (requireNamespace("spelling", quietly = TRUE)) { 2 | spelling::spell_check_test( 3 | vignettes = TRUE, error = FALSE, 4 | skip_on_cran = TRUE 5 | ) 6 | } 7 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(filesstrings) 3 | 4 | test_check("filesstrings") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-files.R: -------------------------------------------------------------------------------- 1 | test_that("nice_file_nums works", { 2 | setwd(tempdir()) 3 | expect_true(dir.create("nice_file_nums_test")) 4 | setwd("nice_file_nums_test") 5 | files <- c("1litres_1.txt", "1litres_30.txt", "3litres_5.txt") 6 | expect_equal(file.create(files), rep(TRUE, 3)) 7 | expect_equal(nice_file_nums(), rep(TRUE, 3)) 8 | expect_equal(nice_file_nums(pattern = "\\.txt$"), rep(TRUE, 3)) 9 | setwd("..") 10 | expect_true(dir.remove("nice_file_nums_test")) 11 | }) 12 | 13 | test_that("remove_filename_spaces works", { 14 | cwd <- setwd(tempdir()) 15 | on.exit(setwd(cwd)) 16 | expect_true(dir.create("remove_filename_spaces_test")) 17 | setwd("remove_filename_spaces_test") 18 | files <- c("1litres 1.txt", "1litres 30.txt", "3litres 5.txt") 19 | expect_equal(file.create(files), rep(TRUE, 3)) 20 | expect_equal(remove_filename_spaces(), rep(TRUE, 3)) 21 | expect_equal(list.files(), c("1litres1.txt", "1litres30.txt", "3litres5.txt")) 22 | expect_equal(remove_filename_spaces(), logical()) 23 | setwd("..") 24 | expect_true(dir.remove("remove_filename_spaces_test")) 25 | file.create(c("1litres 1.txt", "1litres1.txt")) 26 | expect_error( 27 | remove_filename_spaces(), 28 | str_c( 29 | "Not renaming because to do so would also overwrite.*", 30 | "1litres 1.txt.*and.*1litres1.txt.*already exist.*", 31 | "so to rename.*1litres 1.txt.*to.*1litres1.txt.*", 32 | "would be to overwrite.*1litres1.txt" 33 | ) 34 | ) 35 | setwd(cwd) 36 | }) 37 | 38 | test_that("rename_with_nums works", { 39 | cwd <- setwd(tempdir()) 40 | on.exit(setwd(cwd)) 41 | expect_true(dir.create("rename_with_nums_test")) 42 | setwd("rename_with_nums_test") 43 | files <- c("1litres 1.txt", "1litres 30.txt", "3litres 5.txt") 44 | expect_equal(file.create(files), rep(TRUE, 3)) 45 | expect_equal(rename_with_nums(pattern = ".txt$"), rep(TRUE, 3)) 46 | expect_equal(list.files(pattern = ".txt$"), paste0(1:3, ".txt")) 47 | expect_error( 48 | rename_with_nums(), 49 | str_c( 50 | "Some of the names are already in the desired format.*", 51 | "[Uu]nable to proceed as renaming may result in deletion" 52 | ) 53 | ) 54 | file.create("xyz.csv") 55 | expect_error( 56 | rename_with_nums(), 57 | "Files matching pattern have different extensions." 58 | ) 59 | file.remove(dir(pattern = ".txt$")) 60 | file.remove(dir(pattern = ".csv$")) 61 | expect_error(rename_with_nums(pattern = ".txt$"), "No files found to rename.") 62 | setwd("..") 63 | expect_true(dir.remove("rename_with_nums_test")) 64 | setwd(cwd) 65 | }) 66 | 67 | test_that("create_dir works", { 68 | setwd(tempdir()) 69 | expect_equal(create_dir(c("mydir", "yourdir")), rep(TRUE, 2), 70 | check.names = FALSE 71 | ) 72 | expect_equal(create_dir(c("mydir", "yourdir")), rep(FALSE, 2), 73 | check.names = FALSE 74 | ) 75 | expect_equal(dir.remove(c("mydir", "yourdir")), rep(TRUE, 2), 76 | check.names = FALSE 77 | ) 78 | }) 79 | 80 | test_that("unitize_dirs works", { 81 | cwd <- setwd(tempdir()) 82 | on.exit(setwd(cwd)) 83 | expect_equal(dir.create("unitize_dirs_test"), TRUE) 84 | setwd("unitize_dirs_test") 85 | files <- c("1litres_1.txt", "1litres_3.txt", "3litres.txt", "5litres_1.txt") 86 | expect_equal(file.create(files), rep(TRUE, length(files))) 87 | expect_true(unitize_dirs("litres", "\\.txt")) 88 | file.create("10ml.txt") 89 | setwd("..") 90 | expect_error(unitize_dirs("litres")) 91 | expect_true(dir.remove("unitize_dirs_test")) 92 | setwd(cwd) 93 | }) 94 | 95 | test_that("file.move edge cases work correctly", { 96 | cwd <- setwd(tempdir()) 97 | on.exit(setwd(cwd)) 98 | dir.create("tmpdir0") 99 | file.create("tmpfile0.R") 100 | expect_error( 101 | file.move("tmpfile0.R", c("tmpdir0", "tmpdir0")), 102 | "number of destinations must.*1 or.*number of files to be moved" 103 | ) 104 | expect_error( 105 | file.move( 106 | c("tmpfile0.R", "tmpfile0.R"), 107 | c("tmpdir0", "tmpdir0") 108 | ), 109 | "must not have.*duplicated elements.*Element 2.*duplicate" 110 | ) 111 | file.move("tmpfile0.R", "tmpdir0/") 112 | file.create("tmpfile0.R") 113 | expect_message( 114 | file.move("tmpfile0.R", "tmpdir0/"), 115 | "To allow overwriting, use `overwrite = TRUE`" 116 | ) 117 | expect_message( 118 | file.move("tmpfile0.R", "tmpdir0/", overwrite = TRUE), 119 | "1 file moved. 0 failed." 120 | ) 121 | expect_message( 122 | file.move(character(0), character(0)), 123 | "0 files moved. 0 failed." 124 | ) 125 | setwd(cwd) 126 | }) 127 | -------------------------------------------------------------------------------- /tests/testthat/test-roxy.R: -------------------------------------------------------------------------------- 1 | test_that("roxy_files_vignette() works", { 2 | expect_equal( 3 | roxy_files_vignette(), 4 | paste0( 5 | "[vignette]", 6 | "(https://cran.r-project.org/package=filesstrings/vignettes/files.html)." 7 | ) 8 | ) 9 | }) 10 | -------------------------------------------------------------------------------- /tests/testthat/test-strings.R: -------------------------------------------------------------------------------- 1 | test_that("extend_char_vec works", { 2 | expect_equal(extend_char_vec(1:5, extend_by = 2), c(1:5, "", "")) 3 | expect_equal( 4 | extend_char_vec(c("a", "b"), length_out = 10), 5 | c("a", "b", rep("", 8)) 6 | ) 7 | expect_error(extend_char_vec("0")) 8 | expect_error(extend_char_vec(c("0", 3))) 9 | expect_error(extend_char_vec(c("0", "1"), length_out = 1)) 10 | }) 11 | 12 | test_that("put_in_pos works", { 13 | expect_equal(put_in_pos(1:3, c(1, 8, 9)), c(1, rep("", 6), 2, 3)) 14 | expect_equal( 15 | put_in_pos(c("Apple", "Orange", "County"), c(5, 7, 8)), 16 | c(rep("", 4), "Apple", "", "Orange", "County") 17 | ) 18 | expect_equal(put_in_pos(1:2, 5), c(rep("", 4), 1:2)) 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-utils.R: -------------------------------------------------------------------------------- 1 | test_that("all_equal works", { 2 | expect_true(all_equal(1, rep(1, 3))) 3 | expect_true(all_equal(rep(1, 3), 1)) 4 | expect_false(all_equal(2, 1:3)) 5 | expect_true(all_equal(1:4, 1:4)) 6 | expect_false(all_equal(1:4, c(1, 2, 3, 3))) 7 | expect_true(all_equal(rep(1, 10))) 8 | expect_false(all_equal(c(1, 88))) 9 | expect_false(all_equal(character(0), NA)) 10 | expect_false(all_equal(NA, character(0))) 11 | expect_false(all_equal(NULL, NA)) 12 | expect_true(all_equal(matrix(1:4, nrow = 2), matrix(1:4, nrow = 2))) 13 | expect_false(all_equal(array(1, dim = c(2, 2, 2)), 99)) 14 | expect_false(all_equal(99, array(1, dim = c(2, 2, 2)))) 15 | expect_false(all_equal( 16 | array(1, dim = c(2, 2, 2)), 17 | array(1, dim = c(3, 3, 3)) 18 | )) 19 | expect_false(all_equal(matrix(1:4, nrow = 2), 1:3)) 20 | expect_false(all_equal(1:3, matrix(1:4, nrow = 2))) 21 | expect_true(all_equal(list(1, 1))) 22 | }) 23 | 24 | test_that("group_close works", { 25 | expect_equal(group_close(1:10, 1), list(1:10)) 26 | expect_equal(group_close(1:10, 0.5), as.list(1:10)) 27 | expect_equal( 28 | group_close(c(1, 2, 4, 10, 11, 14, 20, 25, 27), 3), 29 | list(c(1, 2, 4), c(10, 11, 14), 20, c(25, 27)) 30 | ) 31 | expect_error(group_close(integer(0))) 32 | expect_error(group_close(rep(1, 2))) 33 | expect_equal(group_close(0), list(0)) 34 | expect_equal(group_close(c(0, 2)), list(0, 2)) 35 | }) 36 | -------------------------------------------------------------------------------- /vignettes/files.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Files" 3 | author: "Rory Nolan" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{Files} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r setup, include=FALSE} 13 | knitr::opts_chunk$set(echo = TRUE, comment = "#>") 14 | ``` 15 | 16 | Here are some useful things which `filesstrings` makes easier than `base` or `fs`. 17 | 18 | First let's load the library: 19 | ```{r load} 20 | library(filesstrings) 21 | ``` 22 | 23 | ## Remove spaces from file names 24 | "A space in your file name is a hole in your soul." - Jenny Bryan 25 | 26 | `remove_filename_spaces(replacement = "_")` replaces them all with underscores for all files in a directory. By default, they are replaced with nothing. 27 | ```{r, remove_filename_spaces} 28 | file.create(c("file 1.txt", "file 2.txt")) 29 | remove_filename_spaces(pattern = "txt$", replacement = "_") 30 | list.files(pattern = "txt$") 31 | file.remove(list.files(pattern = "txt$")) # clean up 32 | ``` 33 | 34 | ## Messed up file numbering 35 | The microscope I use numbers files with 3 numbers by default, i.e. `file001.tif`, `file002.tif` and so on. This is a problem when the automatic numbering passes 1000, whereby we have `file999.tif`, `file1000.tif`. What's the problem with this? Well, sometimes you need alphabetical order to reflect the true order of your files. These file numbers don't satisfy this requirement: 36 | ```{r nice_nums setup} 37 | file.names <- c("file999.tif", "file1000.tif") 38 | sort(file.names) 39 | ``` 40 | so `file1000.tif` comes before `file999.tif` in alphabetical order. The function `nice_nums()` returns the names that we'd like them to have: 41 | ```{r nice_nums} 42 | nice_nums(file.names) 43 | ``` 44 | The function `nice_file_nums` applies such renaming to all the files in an entire directory. It wraps `nice_nums`. 45 | 46 | ## The name of a file without the extension 47 | ```{r before_last_dot} 48 | before_last_dot("spreadsheet_92.csv") 49 | ``` 50 | 51 | ## Ensure that a file name has a given extension 52 | Add a file extension if needed: 53 | ```{r add file extension 1} 54 | give_ext("xyz", "csv") 55 | ``` 56 | If the file name has the correct extension already, it's left alone: 57 | ```{r add file extension 2} 58 | give_ext("xyz.csv", "csv") 59 | ``` 60 | Change a file extension: 61 | ```{r change file extension} 62 | give_ext("abc.csv", "txt") # tack the new extension onto the end 63 | give_ext("abc.csv", "txt", replace = TRUE) # replace the current extension 64 | ``` 65 | --------------------------------------------------------------------------------