├── .Rbuildignore ├── .Rprofile ├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── DESCRIPTION ├── LICENSE.md ├── Makefile ├── NAMESPACE ├── R ├── automate.R ├── check.R ├── check_package.R ├── docker.R ├── docker_windows_path.R ├── gha.R ├── has.R ├── has_package.R ├── hash.R ├── make.R ├── messages.R ├── reproduce.R ├── rerun.R ├── template.R ├── uses.R ├── yaml.R └── zzz.R ├── README.Rmd ├── README.md ├── codecov.yml ├── inst ├── rstudio │ └── templates │ │ └── project │ │ └── repro.dcf └── templates │ ├── Dockerfile │ ├── Makefile.txt │ ├── Makefile_Docker │ ├── Makefile_Singularity │ ├── Makefile_TORQUE │ ├── Makefile_publish │ ├── clean.R │ ├── dockerignore │ ├── forward.sh │ ├── markdown.Rmd │ ├── publish.yml │ └── push-container.yml ├── man ├── automate.Rd ├── automate_load.Rd ├── check.Rd ├── check_package.Rd ├── current_hash.Rd ├── docker.Rd ├── docker_windows_path.Rd ├── has.Rd ├── has_package.Rd ├── make.Rd ├── reproduce.Rd ├── reproduce_funs.Rd ├── rerun.Rd ├── template.Rd ├── use_docker_packages.Rd ├── use_gha_docker.Rd ├── use_gha_publish.Rd ├── use_template_template.Rd └── uses.Rd ├── prep.R ├── repro.Rproj └── tests ├── testthat.R └── testthat ├── helper.R ├── helper_testfiles.R ├── helper_usethis.R ├── setup-opts.R ├── teardown-opts.R ├── test-automate.R ├── test-check.R ├── test-docker.R ├── test-docker_windows_path.R ├── test-gha.R ├── test-hash.R ├── test-make.R ├── test-reproduce.R ├── test-rerun.R ├── test-uses.R ├── test-yaml.R └── test-zzz.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^CODE_OF_CONDUCT\.md$ 5 | ^README\.Rmd$ 6 | ^\.travis\.yml$ 7 | ^codecov\.yml$ 8 | ^prep.R$ 9 | ^Makefile$ 10 | ^\.github$ 11 | -------------------------------------------------------------------------------- /.Rprofile: -------------------------------------------------------------------------------- 1 | if (interactive()) { 2 | suppressMessages(require(devtools)) 3 | suppressMessages(require(usethis)) 4 | suppressMessages(require(testthat)) 5 | } -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/master/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] 6 | pull_request: 7 | branches: [main] 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@v1 35 | 36 | - uses: r-lib/actions/setup-r@v1 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@v1 43 | with: 44 | extra-packages: rcmdcheck 45 | 46 | - uses: r-lib/actions/check-r-package@v1 47 | 48 | - name: Show testthat output 49 | if: always() 50 | run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true 51 | shell: bash 52 | 53 | - name: Upload check results 54 | if: failure() 55 | uses: actions/upload-artifact@main 56 | with: 57 | name: ${{ runner.os }}-r${{ matrix.config.r }}-results 58 | path: check 59 | 60 | - name: Test coverage 61 | if: matrix.config.os == 'ubuntu-latest' && matrix.config.r == 'release' 62 | run: | 63 | remotes::install_cran("covr") 64 | covr::codecov(token = "${{secrets.CODECOV_TOKEN}}") 65 | shell: Rscript {0} 66 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | -------------------------------------------------------------------------------- /CODE_OF_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 | (https://www.contributor-covenant.org), version 1.0.0, available at 25 | https://contributor-covenant.org/version/1/0/0/. 26 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: repro 2 | Type: Package 3 | Title: Automated Setup of Reproducible Workflows and their Dependencies 4 | Version: 0.1.0 5 | Authors@R: c( 6 | person( 7 | "Aaron", 8 | "Peikert", 9 | , 10 | email = "aaron.peikert@posteo.de", 11 | role = c("aut", "cre"), 12 | comment = c(ORCID = "0000-0001-7813-818X") 13 | ), 14 | person( 15 | c("Andreas", "M."), 16 | "Brandmaier", 17 | role = "aut", 18 | comment = c(ORCID = "0000-0001-8765-6982") 19 | ), 20 | person( 21 | given = c("Caspar", "J."), 22 | family = "van Lissa", 23 | email = "c.j.vanlissa@uu.nl", 24 | role = "aut", 25 | comment = c(ORCID = "0000-0002-0808-5024") 26 | ) 27 | ) 28 | Description: Set up components for reproducible workflows, quickly and painlessly. 29 | Apply best practises from 30 | [Peikert & Brandmaier (2019)](), 31 | [Van Lissa et. al 2020]() or 32 | [The Turing Way Community]() 33 | easily in your own projects. 34 | Based upon the great [`usethis`-package](). 35 | License: GPL-3 36 | Encoding: UTF-8 37 | LazyData: true 38 | Roxygen: list(markdown = TRUE) 39 | RoxygenNote: 7.2.1 40 | Depends: R (>= 3.6.0) 41 | Imports: 42 | usethis (>= 1.5.1), 43 | xfun, 44 | fs, 45 | glue, 46 | stringr, 47 | yaml, 48 | rstudioapi, 49 | rmarkdown, 50 | credentials, 51 | gh (>= 1.2.1) 52 | URL: https://github.com/aaronpeikert/repro 53 | BugReports: https://github.com/aaronpeikert/repro/issues 54 | Suggests: 55 | testthat (>= 2.1.0), 56 | covr, 57 | curl, 58 | withr, 59 | rlang, 60 | knitr, 61 | cli, 62 | stringi, 63 | remotes, 64 | gert 65 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU General Public License 2 | ========================== 3 | 4 | _Version 3, 29 June 2007_ 5 | _Copyright © 2007 Free Software Foundation, Inc. <>_ 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this license 8 | document, but changing it is not allowed. 9 | 10 | ## Preamble 11 | 12 | The GNU General Public License is a free, copyleft license for software and other 13 | kinds of works. 14 | 15 | The licenses for most software and other practical works are designed to take away 16 | your freedom to share and change the works. By contrast, the GNU General Public 17 | License is intended to guarantee your freedom to share and change all versions of a 18 | program--to make sure it remains free software for all its users. We, the Free 19 | Software Foundation, use the GNU General Public License for most of our software; it 20 | applies also to any other work released this way by its authors. You can apply it to 21 | your programs, too. 22 | 23 | When we speak of free software, we are referring to freedom, not price. Our General 24 | Public Licenses are designed to make sure that you have the freedom to distribute 25 | copies of free software (and charge for them if you wish), that you receive source 26 | code or can get it if you want it, that you can change the software or use pieces of 27 | it in new 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 these rights or 30 | asking you to surrender the rights. Therefore, you have certain responsibilities if 31 | you distribute copies of the software, or if you modify it: responsibilities to 32 | respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether gratis or for a fee, 35 | you must pass on to the recipients the same freedoms that you received. You must make 36 | sure that they, too, receive or can get the source code. And you must show them these 37 | terms so they know their rights. 38 | 39 | Developers that use the GNU GPL protect your rights with two steps: **(1)** assert 40 | copyright on the software, and **(2)** offer you this License giving you legal permission 41 | to copy, distribute and/or modify it. 42 | 43 | For the developers' and authors' protection, the GPL clearly explains that there is 44 | no warranty for this free software. For both users' and authors' sake, the GPL 45 | requires that modified versions be marked as changed, so that their problems will not 46 | be attributed erroneously to authors of previous versions. 47 | 48 | Some devices are designed to deny users access to install or run modified versions of 49 | the software inside them, although the manufacturer can do so. This is fundamentally 50 | incompatible with the aim of protecting users' freedom to change the software. The 51 | systematic pattern of such abuse occurs in the area of products for individuals to 52 | use, which is precisely where it is most unacceptable. Therefore, we have designed 53 | this version of the GPL to prohibit the practice for those products. If such problems 54 | arise substantially in other domains, we stand ready to extend this provision to 55 | those domains in future versions of the GPL, as needed to protect the freedom of 56 | users. 57 | 58 | Finally, every program is threatened constantly by software patents. States should 59 | not allow patents to restrict development and use of software on general-purpose 60 | computers, but in those that do, we wish to avoid the special danger that patents 61 | applied to a free program could make it effectively proprietary. To prevent this, the 62 | GPL assures that patents cannot be used to render the program non-free. 63 | 64 | The precise terms and conditions for copying, distribution and modification follow. 65 | 66 | ## TERMS AND CONDITIONS 67 | 68 | ### 0. Definitions 69 | 70 | “This License” refers to version 3 of the GNU General Public License. 71 | 72 | “Copyright” also means copyright-like laws that apply to other kinds of 73 | works, such as semiconductor masks. 74 | 75 | “The Program” refers to any copyrightable work licensed under this 76 | License. Each licensee is addressed as “you”. “Licensees” and 77 | “recipients” may be individuals or organizations. 78 | 79 | To “modify” a work means to copy from or adapt all or part of the work in 80 | a fashion requiring copyright permission, other than the making of an exact copy. The 81 | resulting work is called a “modified version” of the earlier work or a 82 | work “based on” the earlier work. 83 | 84 | A “covered work” means either the unmodified Program or a work based on 85 | the Program. 86 | 87 | To “propagate” a work means to do anything with it that, without 88 | permission, would make you directly or secondarily liable for infringement under 89 | applicable copyright law, except executing it on a computer or modifying a private 90 | copy. Propagation includes copying, distribution (with or without modification), 91 | making available to the public, and in some countries other activities as well. 92 | 93 | To “convey” a work means any kind of propagation that enables other 94 | parties to make or receive copies. Mere interaction with a user through a computer 95 | network, with no transfer of a copy, is not conveying. 96 | 97 | An interactive user interface displays “Appropriate Legal Notices” to the 98 | extent that it includes a convenient and prominently visible feature that **(1)** 99 | displays an appropriate copyright notice, and **(2)** tells the user that there is no 100 | warranty for the work (except to the extent that warranties are provided), that 101 | licensees may convey the work under this License, and how to view a copy of this 102 | License. If the interface presents a list of user commands or options, such as a 103 | menu, a prominent item in the list meets this criterion. 104 | 105 | ### 1. Source Code 106 | 107 | The “source code” for a work means the preferred form of the work for 108 | making modifications to it. “Object code” means any non-source form of a 109 | work. 110 | 111 | A “Standard Interface” means an interface that either is an official 112 | standard defined by a recognized standards body, or, in the case of interfaces 113 | specified for a particular programming language, one that is widely used among 114 | developers working in that language. 115 | 116 | The “System Libraries” of an executable work include anything, other than 117 | the work as a whole, that **(a)** is included in the normal form of packaging a Major 118 | Component, but which is not part of that Major Component, and **(b)** serves only to 119 | enable use of the work with that Major Component, or to implement a Standard 120 | Interface for which an implementation is available to the public in source code form. 121 | A “Major Component”, in this context, means a major essential component 122 | (kernel, window system, and so on) of the specific operating system (if any) on which 123 | the executable work runs, or a compiler used to produce the work, or an object code 124 | interpreter used to run it. 125 | 126 | The “Corresponding Source” for a work in object code form means all the 127 | source code needed to generate, install, and (for an executable work) run the object 128 | code and to modify the work, including scripts to control those activities. However, 129 | it does not include the work's System Libraries, or general-purpose tools or 130 | generally available free programs which are used unmodified in performing those 131 | activities but which are not part of the work. For example, Corresponding Source 132 | includes interface definition files associated with source files for the work, and 133 | the source code for shared libraries and dynamically linked subprograms that the work 134 | is specifically designed to require, such as by intimate data communication or 135 | control flow between those subprograms and other parts of the work. 136 | 137 | The Corresponding Source need not include anything that users can regenerate 138 | automatically from other parts of the Corresponding Source. 139 | 140 | The Corresponding Source for a work in source code form is that same work. 141 | 142 | ### 2. Basic Permissions 143 | 144 | All rights granted under this License are granted for the term of copyright on the 145 | Program, and are irrevocable provided the stated conditions are met. This License 146 | explicitly affirms your unlimited permission to run the unmodified Program. The 147 | output from running a covered work is covered by this License only if the output, 148 | given its content, constitutes a covered work. This License acknowledges your rights 149 | of fair use or other equivalent, as provided by copyright law. 150 | 151 | You may make, run and propagate covered works that you do not convey, without 152 | conditions so long as your license otherwise remains in force. You may convey covered 153 | works to others for the sole purpose of having them make modifications exclusively 154 | for you, or provide you with facilities for running those works, provided that you 155 | comply with the terms of this License in conveying all material for which you do not 156 | control copyright. Those thus making or running the covered works for you must do so 157 | exclusively on your behalf, under your direction and control, on terms that prohibit 158 | them from making any copies of your copyrighted material outside their relationship 159 | with you. 160 | 161 | Conveying under any other circumstances is permitted solely under the conditions 162 | stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 163 | 164 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law 165 | 166 | No covered work shall be deemed part of an effective technological measure under any 167 | applicable law fulfilling obligations under article 11 of the WIPO copyright treaty 168 | adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention 169 | of such measures. 170 | 171 | When you convey a covered work, you waive any legal power to forbid circumvention of 172 | technological measures to the extent such circumvention is effected by exercising 173 | rights under this License with respect to the covered work, and you disclaim any 174 | intention to limit operation or modification of the work as a means of enforcing, 175 | against the work's users, your or third parties' legal rights to forbid circumvention 176 | of technological measures. 177 | 178 | ### 4. Conveying Verbatim Copies 179 | 180 | You may convey verbatim copies of the Program's source code as you receive it, in any 181 | medium, provided that you conspicuously and appropriately publish on each copy an 182 | appropriate copyright notice; keep intact all notices stating that this License and 183 | any non-permissive terms added in accord with section 7 apply to the code; keep 184 | intact all notices of the absence of any warranty; and give all recipients a copy of 185 | this License along with the Program. 186 | 187 | You may charge any price or no price for each copy that you convey, and you may offer 188 | support or warranty protection for a fee. 189 | 190 | ### 5. Conveying Modified Source Versions 191 | 192 | You may convey a work based on the Program, or the modifications to produce it from 193 | the Program, in the form of source code under the terms of section 4, provided that 194 | you also meet all of these conditions: 195 | 196 | * **a)** The work must carry prominent notices stating that you modified it, and giving a 197 | relevant date. 198 | * **b)** The work must carry prominent notices stating that it is released under this 199 | License and any conditions added under section 7. This requirement modifies the 200 | requirement in section 4 to “keep intact all notices”. 201 | * **c)** You must license the entire work, as a whole, under this License to anyone who 202 | comes into possession of a copy. This License will therefore apply, along with any 203 | applicable section 7 additional terms, to the whole of the work, and all its parts, 204 | regardless of how they are packaged. This License gives no permission to license the 205 | work in any other way, but it does not invalidate such permission if you have 206 | separately received it. 207 | * **d)** If the work has interactive user interfaces, each must display Appropriate Legal 208 | Notices; however, if the Program has interactive interfaces that do not display 209 | Appropriate Legal Notices, your work need not make them do so. 210 | 211 | A compilation of a covered work with other separate and independent works, which are 212 | not by their nature extensions of the covered work, and which are not combined with 213 | it such as to form a larger program, in or on a volume of a storage or distribution 214 | medium, is called an “aggregate” if the compilation and its resulting 215 | copyright are not used to limit the access or legal rights of the compilation's users 216 | beyond what the individual works permit. Inclusion of a covered work in an aggregate 217 | does not cause this License to apply to the other parts of the aggregate. 218 | 219 | ### 6. Conveying Non-Source Forms 220 | 221 | You may convey a covered work in object code form under the terms of sections 4 and 222 | 5, provided that you also convey the machine-readable Corresponding Source under the 223 | terms of this License, in one of these ways: 224 | 225 | * **a)** Convey the object code in, or embodied in, a physical product (including a 226 | physical distribution medium), accompanied by the Corresponding Source fixed on a 227 | durable physical medium customarily used for software interchange. 228 | * **b)** Convey the object code in, or embodied in, a physical product (including a 229 | physical distribution medium), accompanied by a written offer, valid for at least 230 | three years and valid for as long as you offer spare parts or customer support for 231 | that product model, to give anyone who possesses the object code either **(1)** a copy of 232 | the Corresponding Source for all the software in the product that is covered by this 233 | License, on a durable physical medium customarily used for software interchange, for 234 | a price no more than your reasonable cost of physically performing this conveying of 235 | source, or **(2)** access to copy the Corresponding Source from a network server at no 236 | charge. 237 | * **c)** Convey individual copies of the object code with a copy of the written offer to 238 | provide the Corresponding Source. This alternative is allowed only occasionally and 239 | noncommercially, and only if you received the object code with such an offer, in 240 | accord with subsection 6b. 241 | * **d)** Convey the object code by offering access from a designated place (gratis or for 242 | a charge), and offer equivalent access to the Corresponding Source in the same way 243 | through the same place at no further charge. You need not require recipients to copy 244 | the Corresponding Source along with the object code. If the place to copy the object 245 | code is a network server, the Corresponding Source may be on a different server 246 | (operated by you or a third party) that supports equivalent copying facilities, 247 | provided you maintain clear directions next to the object code saying where to find 248 | the Corresponding Source. Regardless of what server hosts the Corresponding Source, 249 | you remain obligated to ensure that it is available for as long as needed to satisfy 250 | these requirements. 251 | * **e)** Convey the object code using peer-to-peer transmission, provided you inform 252 | other peers where the object code and Corresponding Source of the work are being 253 | offered to the general public at no charge under subsection 6d. 254 | 255 | A separable portion of the object code, whose source code is excluded from the 256 | Corresponding Source as a System Library, need not be included in conveying the 257 | object code work. 258 | 259 | A “User Product” is either **(1)** a “consumer product”, which 260 | means any tangible personal property which is normally used for personal, family, or 261 | household purposes, or **(2)** anything designed or sold for incorporation into a 262 | dwelling. In determining whether a product is a consumer product, doubtful cases 263 | shall be resolved in favor of coverage. For a particular product received by a 264 | particular user, “normally used” refers to a typical or common use of 265 | that class of product, regardless of the status of the particular user or of the way 266 | in which the particular user actually uses, or expects or is expected to use, the 267 | product. A product is a consumer product regardless of whether the product has 268 | substantial commercial, industrial or non-consumer uses, unless such uses represent 269 | the only significant mode of use of the product. 270 | 271 | “Installation Information” for a User Product means any methods, 272 | procedures, authorization keys, or other information required to install and execute 273 | modified versions of a covered work in that User Product from a modified version of 274 | its Corresponding Source. The information must suffice to ensure that the continued 275 | functioning of the modified object code is in no case prevented or interfered with 276 | solely because modification has been made. 277 | 278 | If you convey an object code work under this section in, or with, or specifically for 279 | use in, a User Product, and the conveying occurs as part of a transaction in which 280 | the right of possession and use of the User Product is transferred to the recipient 281 | in perpetuity or for a fixed term (regardless of how the transaction is 282 | characterized), the Corresponding Source conveyed under this section must be 283 | accompanied by the Installation Information. But this requirement does not apply if 284 | neither you nor any third party retains the ability to install modified object code 285 | on the User Product (for example, the work has been installed in ROM). 286 | 287 | The requirement to provide Installation Information does not include a requirement to 288 | continue to provide support service, warranty, or updates for a work that has been 289 | modified or installed by the recipient, or for the User Product in which it has been 290 | modified or installed. Access to a network may be denied when the modification itself 291 | materially and adversely affects the operation of the network or violates the rules 292 | and protocols for communication across the network. 293 | 294 | Corresponding Source conveyed, and Installation Information provided, in accord with 295 | this section must be in a format that is publicly documented (and with an 296 | implementation available to the public in source code form), and must require no 297 | special password or key for unpacking, reading or copying. 298 | 299 | ### 7. Additional Terms 300 | 301 | “Additional permissions” are terms that supplement the terms of this 302 | License by making exceptions from one or more of its conditions. Additional 303 | permissions that are applicable to the entire Program shall be treated as though they 304 | were included in this License, to the extent that they are valid under applicable 305 | law. If additional permissions apply only to part of the Program, that part may be 306 | used separately under those permissions, but the entire Program remains governed by 307 | this License without regard to the additional permissions. 308 | 309 | When you convey a copy of a covered work, you may at your option remove any 310 | additional permissions from that copy, or from any part of it. (Additional 311 | permissions may be written to require their own removal in certain cases when you 312 | modify the work.) You may place additional permissions on material, added by you to a 313 | covered work, for which you have or can give appropriate copyright permission. 314 | 315 | Notwithstanding any other provision of this License, for material you add to a 316 | covered work, you may (if authorized by the copyright holders of that material) 317 | supplement the terms of this License with terms: 318 | 319 | * **a)** Disclaiming warranty or limiting liability differently from the terms of 320 | sections 15 and 16 of this License; or 321 | * **b)** Requiring preservation of specified reasonable legal notices or author 322 | attributions in that material or in the Appropriate Legal Notices displayed by works 323 | containing it; or 324 | * **c)** Prohibiting misrepresentation of the origin of that material, or requiring that 325 | modified versions of such material be marked in reasonable ways as different from the 326 | original version; or 327 | * **d)** Limiting the use for publicity purposes of names of licensors or authors of the 328 | material; or 329 | * **e)** Declining to grant rights under trademark law for use of some trade names, 330 | trademarks, or service marks; or 331 | * **f)** Requiring indemnification of licensors and authors of that material by anyone 332 | who conveys the material (or modified versions of it) with contractual assumptions of 333 | liability to the recipient, for any liability that these contractual assumptions 334 | directly impose on those licensors and authors. 335 | 336 | All other non-permissive additional terms are considered “further 337 | restrictions” within the meaning of section 10. If the Program as you received 338 | it, or any part of it, contains a notice stating that it is governed by this License 339 | along with a term that is a further restriction, you may remove that term. If a 340 | license document contains a further restriction but permits relicensing or conveying 341 | under this License, you may add to a covered work material governed by the terms of 342 | that license document, provided that the further restriction does not survive such 343 | relicensing or conveying. 344 | 345 | If you add terms to a covered work in accord with this section, you must place, in 346 | the relevant source files, a statement of the additional terms that apply to those 347 | files, or a notice indicating where to find the applicable terms. 348 | 349 | Additional terms, permissive or non-permissive, may be stated in the form of a 350 | separately written license, or stated as exceptions; the above requirements apply 351 | either way. 352 | 353 | ### 8. Termination 354 | 355 | You may not propagate or modify a covered work except as expressly provided under 356 | this License. Any attempt otherwise to propagate or modify it is void, and will 357 | automatically terminate your rights under this License (including any patent licenses 358 | granted under the third paragraph of section 11). 359 | 360 | However, if you cease all violation of this License, then your license from a 361 | particular copyright holder is reinstated **(a)** provisionally, unless and until the 362 | copyright holder explicitly and finally terminates your license, and **(b)** permanently, 363 | if the copyright holder fails to notify you of the violation by some reasonable means 364 | prior to 60 days after the cessation. 365 | 366 | Moreover, your license from a particular copyright holder is reinstated permanently 367 | if the copyright holder notifies you of the violation by some reasonable means, this 368 | is the first time you have received notice of violation of this License (for any 369 | work) from that copyright holder, and you cure the violation prior to 30 days after 370 | your receipt of the notice. 371 | 372 | Termination of your rights under this section does not terminate the licenses of 373 | parties who have received copies or rights from you under this License. If your 374 | rights have been terminated and not permanently reinstated, you do not qualify to 375 | receive new licenses for the same material under section 10. 376 | 377 | ### 9. Acceptance Not Required for Having Copies 378 | 379 | You are not required to accept this License in order to receive or run a copy of the 380 | Program. Ancillary propagation of a covered work occurring solely as a consequence of 381 | using peer-to-peer transmission to receive a copy likewise does not require 382 | acceptance. However, nothing other than this License grants you permission to 383 | propagate or modify any covered work. These actions infringe copyright if you do not 384 | accept this License. Therefore, by modifying or propagating a covered work, you 385 | indicate your acceptance of this License to do so. 386 | 387 | ### 10. Automatic Licensing of Downstream Recipients 388 | 389 | Each time you convey a covered work, the recipient automatically receives a license 390 | from the original licensors, to run, modify and propagate that work, subject to this 391 | License. You are not responsible for enforcing compliance by third parties with this 392 | License. 393 | 394 | An “entity transaction” is a transaction transferring control of an 395 | organization, or substantially all assets of one, or subdividing an organization, or 396 | merging organizations. If propagation of a covered work results from an entity 397 | transaction, each party to that transaction who receives a copy of the work also 398 | receives whatever licenses to the work the party's predecessor in interest had or 399 | could give under the previous paragraph, plus a right to possession of the 400 | Corresponding Source of the work from the predecessor in interest, if the predecessor 401 | has it or can get it with reasonable efforts. 402 | 403 | You may not impose any further restrictions on the exercise of the rights granted or 404 | affirmed under this License. For example, you may not impose a license fee, royalty, 405 | or other charge for exercise of rights granted under this License, and you may not 406 | initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging 407 | that any patent claim is infringed by making, using, selling, offering for sale, or 408 | importing the Program or any portion of it. 409 | 410 | ### 11. Patents 411 | 412 | A “contributor” is a copyright holder who authorizes use under this 413 | License of the Program or a work on which the Program is based. The work thus 414 | licensed is called the contributor's “contributor version”. 415 | 416 | A contributor's “essential patent claims” are all patent claims owned or 417 | controlled by the contributor, whether already acquired or hereafter acquired, that 418 | would be infringed by some manner, permitted by this License, of making, using, or 419 | selling its contributor version, but do not include claims that would be infringed 420 | only as a consequence of further modification of the contributor version. For 421 | purposes of this definition, “control” includes the right to grant patent 422 | sublicenses in a manner consistent with the requirements of this License. 423 | 424 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license 425 | under the contributor's essential patent claims, to make, use, sell, offer for sale, 426 | import and otherwise run, modify and propagate the contents of its contributor 427 | version. 428 | 429 | In the following three paragraphs, a “patent license” is any express 430 | agreement or commitment, however denominated, not to enforce a patent (such as an 431 | express permission to practice a patent or covenant not to sue for patent 432 | infringement). To “grant” such a patent license to a party means to make 433 | such an agreement or commitment not to enforce a patent against the party. 434 | 435 | If you convey a covered work, knowingly relying on a patent license, and the 436 | Corresponding Source of the work is not available for anyone to copy, free of charge 437 | and under the terms of this License, through a publicly available network server or 438 | other readily accessible means, then you must either **(1)** cause the Corresponding 439 | Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the 440 | patent license for this particular work, or **(3)** arrange, in a manner consistent with 441 | the requirements of this License, to extend the patent license to downstream 442 | recipients. “Knowingly relying” means you have actual knowledge that, but 443 | for the patent license, your conveying the covered work in a country, or your 444 | recipient's use of the covered work in a country, would infringe one or more 445 | identifiable patents in that country that you have reason to believe are valid. 446 | 447 | If, pursuant to or in connection with a single transaction or arrangement, you 448 | convey, or propagate by procuring conveyance of, a covered work, and grant a patent 449 | license to some of the parties receiving the covered work authorizing them to use, 450 | propagate, modify or convey a specific copy of the covered work, then the patent 451 | license you grant is automatically extended to all recipients of the covered work and 452 | works based on it. 453 | 454 | A patent license is “discriminatory” if it does not include within the 455 | scope of its coverage, prohibits the exercise of, or is conditioned on the 456 | non-exercise of one or more of the rights that are specifically granted under this 457 | License. You may not convey a covered work if you are a party to an arrangement with 458 | a third party that is in the business of distributing software, under which you make 459 | payment to the third party based on the extent of your activity of conveying the 460 | work, and under which the third party grants, to any of the parties who would receive 461 | the covered work from you, a discriminatory patent license **(a)** in connection with 462 | copies of the covered work conveyed by you (or copies made from those copies), or **(b)** 463 | primarily for and in connection with specific products or compilations that contain 464 | the covered work, unless you entered into that arrangement, or that patent license 465 | was granted, prior to 28 March 2007. 466 | 467 | Nothing in this License shall be construed as excluding or limiting any implied 468 | license or other defenses to infringement that may otherwise be available to you 469 | under applicable patent law. 470 | 471 | ### 12. No Surrender of Others' Freedom 472 | 473 | If conditions are imposed on you (whether by court order, agreement or otherwise) 474 | that contradict the conditions of this License, they do not excuse you from the 475 | conditions of this License. If you cannot convey a covered work so as to satisfy 476 | simultaneously your obligations under this License and any other pertinent 477 | obligations, then as a consequence you may not convey it at all. For example, if you 478 | agree to terms that obligate you to collect a royalty for further conveying from 479 | those to whom you convey the Program, the only way you could satisfy both those terms 480 | and this License would be to refrain entirely from conveying the Program. 481 | 482 | ### 13. Use with the GNU Affero General Public License 483 | 484 | Notwithstanding any other provision of this License, you have permission to link or 485 | combine any covered work with a work licensed under version 3 of the GNU Affero 486 | General Public License into a single combined work, and to convey the resulting work. 487 | The terms of this License will continue to apply to the part which is the covered 488 | work, but the special requirements of the GNU Affero General Public License, section 489 | 13, concerning interaction through a network will apply to the combination as such. 490 | 491 | ### 14. Revised Versions of this License 492 | 493 | The Free Software Foundation may publish revised and/or new versions of the GNU 494 | General Public License from time to time. Such new versions will be similar in spirit 495 | to the present version, but may differ in detail to address new problems or concerns. 496 | 497 | Each version is given a distinguishing version number. If the Program specifies that 498 | a certain numbered version of the GNU General Public License “or any later 499 | version” applies to it, you have the option of following the terms and 500 | conditions either of that numbered version or of any later version published by the 501 | Free Software Foundation. If the Program does not specify a version number of the GNU 502 | General Public License, you may choose any version ever published by the Free 503 | Software Foundation. 504 | 505 | If the Program specifies that a proxy can decide which future versions of the GNU 506 | General Public License can be used, that proxy's public statement of acceptance of a 507 | version permanently authorizes you to choose that version for the Program. 508 | 509 | Later license versions may give you additional or different permissions. However, no 510 | additional obligations are imposed on any author or copyright holder as a result of 511 | your choosing to follow a later version. 512 | 513 | ### 15. Disclaimer of Warranty 514 | 515 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 516 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 517 | PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER 518 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 519 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE 520 | QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE 521 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 522 | 523 | ### 16. Limitation of Liability 524 | 525 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY 526 | COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS 527 | PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, 528 | INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 529 | PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE 530 | OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE 531 | WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 532 | POSSIBILITY OF SUCH DAMAGES. 533 | 534 | ### 17. Interpretation of Sections 15 and 16 535 | 536 | If the disclaimer of warranty and limitation of liability provided above cannot be 537 | given local legal effect according to their terms, reviewing courts shall apply local 538 | law that most closely approximates an absolute waiver of all civil liability in 539 | connection with the Program, unless a warranty or assumption of liability accompanies 540 | a copy of the Program in return for a fee. 541 | 542 | _END OF TERMS AND CONDITIONS_ 543 | 544 | ## How to Apply These Terms to Your New Programs 545 | 546 | If you develop a new program, and you want it to be of the greatest possible use to 547 | the public, the best way to achieve this is to make it free software which everyone 548 | can redistribute and change under these terms. 549 | 550 | To do so, attach the following notices to the program. It is safest to attach them 551 | to the start of each source file to most effectively state the exclusion of warranty; 552 | and each file should have at least the “copyright” line and a pointer to 553 | where the full notice is found. 554 | 555 | 556 | Copyright (C) 2020 Aaron Peikert 557 | 558 | This program is free software: you can redistribute it and/or modify 559 | it under the terms of the GNU General Public License as published by 560 | the Free Software Foundation, either version 3 of the License, or 561 | (at your option) any later version. 562 | 563 | This program is distributed in the hope that it will be useful, 564 | but WITHOUT ANY WARRANTY; without even the implied warranty of 565 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 566 | GNU General Public License for more details. 567 | 568 | You should have received a copy of the GNU General Public License 569 | along with this program. If not, see . 570 | 571 | Also add information on how to contact you by electronic and paper mail. 572 | 573 | If the program does terminal interaction, make it output a short notice like this 574 | when it starts in an interactive mode: 575 | 576 | repro Copyright (C) 2020 Aaron Peikert 577 | This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. 578 | This is free software, and you are welcome to redistribute it 579 | under certain conditions; type 'show c' for details. 580 | 581 | The hypothetical commands `show w` and `show c` should show the appropriate parts of 582 | the General Public License. Of course, your program's commands might be different; 583 | for a GUI interface, you would use an “about box”. 584 | 585 | You should also get your employer (if you work as a programmer) or school, if any, to 586 | sign a “copyright disclaimer” for the program, if necessary. For more 587 | information on this, and how to apply and follow the GNU GPL, see 588 | <>. 589 | 590 | The GNU General Public License does not permit incorporating your program into 591 | proprietary programs. If your program is a subroutine library, you may consider it 592 | more useful to permit linking proprietary applications with the library. If this is 593 | what you want to do, use the GNU Lesser General Public License instead of this 594 | License. But first, please read 595 | <>. 596 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # stolen from https://github.com/cjvanlissa/worcs/blob/02e2e3f01a1e8002e34deafb04725dac8c482c00/Makefile#L1-L27 2 | PKGNAME := $(shell sed -n "s/Package: *\([^ ]*\)/\1/p" DESCRIPTION) 3 | PKGVERS := $(shell sed -n "s/Version: *\([^ ]*\)/\1/p" DESCRIPTION) 4 | PKGSRC := $(shell basename `pwd`) 5 | 6 | all: rd readme check clean 7 | 8 | # pkgdown: 9 | # Rscript -e 'pkgdown::build_site()' 10 | 11 | rd: 12 | Rscript -e 'roxygen2::roxygenise(".")' 13 | 14 | readme: 15 | Rscript -e 'rmarkdown::render("README.rmd", "md_document")' 16 | 17 | build: 18 | cd ..;\ 19 | R CMD build $(PKGSRC) 20 | 21 | install: 22 | cd ..;\ 23 | R CMD INSTALL $(PKGNAME)_$(PKGVERS).tar.gz 24 | 25 | check: build 26 | cd ..;\ 27 | R CMD check --as-cran $(PKGNAME)_$(PKGVERS).tar.gz -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(automate) 4 | export(automate_docker) 5 | export(automate_load_data) 6 | export(automate_load_packages) 7 | export(automate_load_scripts) 8 | export(automate_make) 9 | export(automate_publish) 10 | export(check_brew) 11 | export(check_choco) 12 | export(check_docker) 13 | export(check_git) 14 | export(check_github) 15 | export(check_github_ssh) 16 | export(check_github_token) 17 | export(check_github_token_access) 18 | export(check_make) 19 | export(check_package) 20 | export(check_renv) 21 | export(check_ssh) 22 | export(check_targets) 23 | export(check_worcs) 24 | export(current_hash) 25 | export(docker_windows_path) 26 | export(has_brew) 27 | export(has_choco) 28 | export(has_docker) 29 | export(has_docker_running) 30 | export(has_gert) 31 | export(has_git) 32 | export(has_github) 33 | export(has_github_ssh) 34 | export(has_github_token) 35 | export(has_github_token_access) 36 | export(has_make) 37 | export(has_package) 38 | export(has_renv) 39 | export(has_ssh) 40 | export(has_targets) 41 | export(has_worcs) 42 | export(repro_template) 43 | export(reproduce) 44 | export(reproduce_funs) 45 | export(reproduce_make) 46 | export(rerun) 47 | export(use_docker) 48 | export(use_docker_packages) 49 | export(use_dockerignore) 50 | export(use_gha_docker) 51 | export(use_gha_publish) 52 | export(use_make) 53 | export(use_make_docker) 54 | export(use_make_publish) 55 | export(use_make_singularity) 56 | export(use_repro_template) 57 | export(uses_docker) 58 | export(uses_gha_docker) 59 | export(uses_gha_publish) 60 | export(uses_make) 61 | export(uses_make_publish) 62 | export(uses_make_rmds) 63 | -------------------------------------------------------------------------------- /R/automate.R: -------------------------------------------------------------------------------- 1 | #' Automate the use of Docker & Make 2 | #' 3 | #' `automate()` & friends use yaml metadata from RMarkdowns to create 4 | #' `Dockerfile`'s and `Makefile`'s. It should be clear which is created by 5 | #' `automate_docker()` & which by `automate_make()`. 6 | #' @param path Where should we look for RMarkdowns? 7 | #' @seealso [automate_load_packages()], [automate_load_data()], [automate_load_scripts()] 8 | #' @name automate 9 | NULL 10 | 11 | #' @rdname automate 12 | #' @export 13 | automate <- function(path = "."){ 14 | automate_docker(path) 15 | #automate_publish(path) 16 | automate_make(path) 17 | if(uses_gha_publish(silent = TRUE)) 18 | automate_make_rmd_check(path, target = "publish/") 19 | return(invisible(NULL)) 20 | } 21 | 22 | #' @rdname automate 23 | #' @export 24 | automate_make <- function(path = "."){ 25 | automate_make_rmd(path) 26 | # automate_make_bookdown() 27 | use_make(docker = FALSE, singularity = FALSE, torque = FALSE) 28 | if(uses_make_rmds(silent = TRUE)) 29 | automate_make_rmd_check(path, target ="all") 30 | } 31 | 32 | #' @rdname automate 33 | #' @export 34 | automate_publish <- function(path = "."){ 35 | if(automate_dir()){ 36 | use_gha_docker() 37 | use_gha_publish() 38 | use_make_publish() 39 | automate_make_rmd_check(path = ".", target = "publish/") 40 | } 41 | } 42 | 43 | automate_make_rmd <- function(path){ 44 | if(automate_dir()){ 45 | yamls <- get_yamls(path) 46 | entries <- lapply(yamls, function(x)do.call(yaml_to_make, x)) 47 | entries <- sort(unlist(entries)) 48 | if(is.null(entries))xfun::write_utf8("", getOption("repro.makefile.rmds")) 49 | else { 50 | entries <- stringr::str_c(entries, "\n", collapse = "\n") 51 | xfun::write_utf8(entries, getOption("repro.makefile.rmds")) 52 | } 53 | usethis::ui_done("Writing {usethis::ui_path(getOption('repro.makefile.rmds'))}") 54 | } 55 | } 56 | 57 | automate_make_rmd_check <- function(path, edit = FALSE, target = "all"){ 58 | if(!uses_make(silent = TRUE)){ 59 | return(invisible()) 60 | } 61 | yamls <- get_yamls(path) 62 | output_files <- lapply(yamls, function(x)do.call(get_output_files, x)) 63 | output_files <- unlist(output_files) 64 | makefile <- xfun::read_utf8("Makefile") 65 | target_line <- makefile[stringr::str_detect(makefile, stringr::str_c("^", target, ":"))] 66 | which_missing <- lapply(output_files, function(x)!stringr::str_detect(target_line, x)) 67 | missing <- output_files[unlist(which_missing)] 68 | if (length(target_line) > 1L) { 69 | usethis::ui_oops( 70 | "Ther are multiple {usethis::ui_value('Makefile')}-targets {usethis::ui_value(target)}. This is confusing, so consider joining them into one." 71 | ) 72 | } 73 | else if (length(target_line) == 0L) { 74 | usethis::ui_todo( 75 | "There is no {usethis::ui_value('Makefile')}-target {usethis::ui_value(target)}. Create one with one or more dependencies:\n{usethis::ui_value(output_files)}" 76 | ) 77 | } 78 | else if (length(missing) > 0){ 79 | usethis::ui_todo( 80 | "Maybe you want to add:\n{usethis::ui_value(missing)}\nto the {usethis::ui_value('Makefile')}-target {usethis::ui_value(target)}." 81 | ) 82 | } 83 | if(edit){ 84 | usethis::edit_file("Makefile") 85 | } 86 | } 87 | 88 | yaml_to_make <- function(file, output, data = NULL, scripts = NULL, bibliography = NULL, images = NULL, files = NULL, ...){ 89 | if(missing(file) || missing(output))return(NULL) 90 | output_file <- stringr::str_c(get_output_files(file, output), collapse = " ") 91 | deps <- stringr::str_c(c(file, data, scripts, bibliography, images, files), collapse = " ") 92 | stringr::str_c(output_file, ": ", deps, "\n\t", 93 | "$(RUN1) Rscript -e 'rmarkdown::render(\"$(WORKDIR)/$<\", \"all\")' $(RUN2)") 94 | } 95 | 96 | get_output_files <- function(file, output, ...){ 97 | if(missing(output))return(NULL) 98 | unlist(lapply(output, function(x)get_output_file(file, x))) 99 | } 100 | 101 | get_output_file <- function(file, output){ 102 | get_fun <- function(x) { 103 | # from https://stackoverflow.com/a/38984214/7682760 104 | if(grepl("::", x)) { 105 | parts<-strsplit(x, "::")[[1]] 106 | } else { 107 | parts <- c("rmarkdown", x) 108 | } 109 | getExportedValue(parts[1], parts[2]) 110 | } 111 | render_func <- do.call(get_fun(output), list()) 112 | out <- do.call(utils::getFromNamespace("pandoc_output_file", "rmarkdown"), 113 | list(input = file, 114 | pandoc_options = render_func$pandoc)) 115 | out <- stringr::str_c(dir_name(file), out) 116 | 117 | } 118 | 119 | #' @rdname automate 120 | #' @export 121 | automate_docker <- function(path = "."){ 122 | if(automate_dir()){ 123 | dockerfile_base <- getOption("repro.dockerfile.base") 124 | dockerfile_packages <- getOption("repro.dockerfile.packages") 125 | dockerfile_manual <- getOption("repro.dockerfile.manual") 126 | dockerfile_apt <- getOption("repro.dockerfile.apt") 127 | 128 | # handle base 129 | if(!fs::file_exists(dockerfile_base))use_docker(file = dockerfile_base, 130 | open = FALSE) 131 | # handle apt 132 | docker_apt <- use_docker_apt(yamls_apt(path = usethis::proj_path(path)), 133 | file = dockerfile_base, 134 | write = FALSE, 135 | append = FALSE) 136 | if(length(docker_apt) != 0L){ 137 | xfun::write_utf8(docker_apt, dockerfile_apt) 138 | usethis::ui_done("Writing {usethis::ui_path(dockerfile_apt)}") 139 | } 140 | # handle packages 141 | docker_packages <- use_docker_packages( 142 | yamls_packages(path = usethis::proj_path(path)), 143 | file = dockerfile_base, 144 | github = TRUE, 145 | write = FALSE, 146 | append = FALSE 147 | ) 148 | note <- glue::glue("# Generated by repro: do not edit by hand 149 | Please edit Dockerfiles in {getOption('repro.dockerfile.manual')}/") 150 | xfun::write_utf8(docker_packages, dockerfile_packages) 151 | usethis::ui_done("Writing {usethis::ui_path(dockerfile_packages)}") 152 | 153 | # handle manual 154 | if(!fs::file_exists(dockerfile_manual)){ 155 | fs::file_create(dockerfile_manual) 156 | usethis::ui_done("Writing {usethis::ui_path(getOption('repro.dockerfile.manual'))}") 157 | } 158 | 159 | # bundle dockerfiles 160 | automate_docker_bundle() 161 | } 162 | } 163 | 164 | automate_docker_bundle <- function(file = "Dockerfile"){ 165 | dockerfiles <- c( 166 | dockerfile_base = getOption("repro.dockerfile.base"), 167 | dockerfile_manual = getOption("repro.dockerfile.manual"), 168 | dockerfile_apt = getOption("repro.dockerfile.apt"), 169 | dockerfile_packages = getOption("repro.dockerfile.packages")) 170 | note <- glue::glue("# Generated by repro: do not edit by hand 171 | # Please edit Dockerfiles in {getOption('repro.dir')}/") 172 | to_read <- dockerfiles[unlist(lapply(dockerfiles, fs::file_exists))] 173 | to_write <- c(note, unlist(lapply(to_read, xfun::read_utf8))) 174 | xfun::write_utf8(to_write, file) 175 | usethis::ui_done("Writing {usethis::ui_path(file)}") 176 | } 177 | 178 | automate_dir <- function(dir, warn = FALSE, create = !warn){ 179 | if(missing(dir))dir <- getOption("repro.dir") 180 | dir_full <- usethis::proj_path(dir) 181 | exists <- fs::dir_exists(dir_full) 182 | if(!exists){ 183 | if(warn){ 184 | usethis::ui_oops("Directory {usethis::ui_code(dir)} does not exist!") 185 | } 186 | if(create){ 187 | fs::dir_create(dir_full) 188 | usethis::ui_done("Directory {usethis::ui_code(dir)} created!") 189 | exists <- fs::dir_exists(dir_full) 190 | } 191 | } 192 | if(exists){ 193 | op <- options() 194 | depend_on_dir <- c( 195 | "repro.dockerfile.base", 196 | "repro.dockerfile.packages", 197 | "repro.dockerfile.manual", 198 | "repro.dockerfile.apt", 199 | "repro.makefile.docker", 200 | "repro.makefile.singularity", 201 | "repro.makefile.torque", 202 | "repro.makefile.rmds", 203 | "repro.makefile.publish" 204 | ) 205 | allready_changed <- function(x){ 206 | stringr::str_detect(op[[x]], stringr::str_c("^", op[["repro.dir"]])) 207 | } 208 | to_change <- depend_on_dir[!unlist(lapply(depend_on_dir, allready_changed))] 209 | op.repro <- lapply(to_change, 210 | function(x)stringr::str_c(op[["repro.dir"]], "/", op[[x]])) 211 | names(op.repro) <- to_change 212 | options(op.repro) 213 | } 214 | return(exists) 215 | } 216 | 217 | #' Access repro YAML Metadata from within the document 218 | #' 219 | #' * `automate_load_packages()` loads all packages listed in YAML via `library()` 220 | #' * `automate_load_scripts()` registeres external scripts via `knitr::read_chunk()` 221 | #' * `automate_load_data()` reads in the data from the yaml with abitrary functions 222 | #' 223 | #' @param data How is the entry in the YAML called? It will be the name of the object. 224 | #' @param func Which function should be used to read in the data? Its first argument must be the path to the file. 225 | #' @param ... Further arguments supplied to `func`. 226 | #' @return `automate_load_packages()` & `automate_load_scripts()` do not return anything. `automate_load_data()` returns the data. 227 | #' 228 | #' @name automate_load 229 | NULL 230 | 231 | #' @rdname automate_load 232 | #' @export 233 | automate_load_packages <- function(){ 234 | packages <- yaml_repro_current()$packages 235 | strip_github <- function(x){ 236 | splitted <- stringr::str_split(x, "[/|@]")[[1]] 237 | if(length(splitted) == 1L)return(splitted) 238 | else return(splitted[2]) 239 | } 240 | packages <- lapply(packages, strip_github) 241 | lapply(packages, library, character.only = TRUE, quietly = TRUE) 242 | return(invisible(NULL)) 243 | } 244 | 245 | #' @rdname automate_load 246 | #' @export 247 | automate_load_scripts <- function(){ 248 | paths <- lapply(yaml_repro_current()$scripts, usethis::proj_path) 249 | scripts <- lapply(paths, xfun::read_utf8) 250 | lapply(scripts, function(x)knitr::read_chunk(lines = x)) 251 | return(invisible(NULL)) 252 | } 253 | 254 | #' @rdname automate_load 255 | #' @export 256 | automate_load_data <- function(data, func, ...){ 257 | which <- deparse(substitute(data)) 258 | path <- usethis::proj_path(yaml_repro_current()$data[[which]]) 259 | data <- do.call(func, list(path, ...)) 260 | return(data) 261 | } 262 | -------------------------------------------------------------------------------- /R/check.R: -------------------------------------------------------------------------------- 1 | #' Check System Dependencies 2 | #' 3 | #' Check if a dependency is installed and if not it recommends how to install it 4 | #' depending on the operating system. Most importantly it checks for 5 | #' `git`, `make` & `docker`. And just for convenience of the installation it 6 | #' checks on OS X for `Homebrew` and on Windows for `Chocolately`. 7 | #' @param install Should something be installed? Defaults to "ask", but can be TRUE/FALSE. 8 | #' @param auth_method How do you want to authenticate with GitHub? Either "token" (default) or "ssh". 9 | #' @name check 10 | #' @family checkers 11 | NULL 12 | 13 | #' @rdname check 14 | #' @export 15 | check_docker <- function(){ 16 | if(has_docker_running())has_docker_running(silent = FALSE) 17 | else if(!has_docker(silent = FALSE)){ 18 | msg_install_with_choco("Docker", "choco install -y docker-desktop") 19 | msg_install_with_brew("Docker", "brew install --cask docker", { 20 | usethis::ui_todo("Open 'Docker'/'Docker Desktop for Mac' once to make it available.") 21 | }) 22 | msg_install_with_apt("Docker", "apt install docker", { 23 | usethis::ui_todo("Add your user to the docker user group. Follow instructions on:\n{usethis::ui_value('https://docs.docker.com/install/linux/linux-postinstall/')}") 24 | }) 25 | msg_restart() 26 | usethis::ui_info("For more infos visit:\n{usethis::ui_value('https://docs.docker.com/install/')}") 27 | } 28 | invisible(has_docker()) 29 | } 30 | 31 | #' @rdname check 32 | #' @export 33 | 34 | check_make <- function(){ 35 | if(!has_make(silent = FALSE)){ 36 | choco <- "Chocolately" 37 | msg_install_with_choco(choco, "choco install -y make") 38 | msg_install_with_brew(choco, "brew install make") 39 | msg_install_with_apt(choco, "apt install make") 40 | msg_restart() 41 | } 42 | invisible(has_make()) 43 | } 44 | 45 | #' @rdname check 46 | #' @export 47 | check_git <- function(){ 48 | if(!has_git(silent = FALSE)) { 49 | msg_install_with_choco("Git", "choco install -y git") 50 | msg_install_with_brew("Git", "brew install git") 51 | msg_install_with_apt("Git", "apt install git") 52 | } 53 | invisible(has_git()) 54 | } 55 | 56 | #' @rdname check 57 | #' @export 58 | check_brew <- function(){ 59 | if(!has_brew(silent = FALSE)){ 60 | usethis::ui_todo("To install it, follow directions on:\n{usethis::ui_value('https://docs.brew.sh/Installation')}") 61 | usethis::ui_todo("Restart your computer.") 62 | } 63 | invisible(has_brew()) 64 | } 65 | 66 | #' @rdname check 67 | #' @export 68 | check_choco <- function(){ 69 | if(!has_choco(silent = FALSE)){ 70 | usethis::ui_todo( 71 | "To install it, follow directions on: \n{usethis::ui_value('https://chocolatey.org/docs/installation')}" 72 | ) 73 | usethis::ui_info("Use an administrator terminal to install chocolately.") 74 | usethis::ui_todo("Restart your computer.") 75 | } 76 | invisible(has_choco()) 77 | } 78 | 79 | #' @rdname check 80 | #' @export 81 | check_ssh <- function(install = getOption("repro.install")) { 82 | if (!has_ssh(silent = FALSE)) { 83 | if (install == "ask") 84 | install <- !usethis::ui_nope("Do you want to generate SSH keys?") 85 | if (install) { 86 | options(repro.ssh = dangerous_succeeds(credentials::ssh_keygen)()) 87 | msg_rerun("check_ssh()", " to verify the new ssh keys.") 88 | } 89 | } 90 | invisible(has_ssh()) 91 | } 92 | 93 | #' @rdname check 94 | #' @export 95 | check_github_token <- function(install = getOption("repro.install")){ 96 | if(!has_github_token(silent = FALSE)){ 97 | if(install == "ask")install <- !usethis::ui_nope("Do you want to generate a GitHub token?") 98 | if(install){ 99 | usethis::create_github_token() 100 | msg_rerun("check_github_token()", " to verify the new GitHub token.\nIf the problem persists, try {usethis::ui_code('usethis::gh_token_help()')}.") 101 | } 102 | } 103 | invisible(has_github_token()) 104 | } 105 | 106 | #' @rdname check 107 | #' @export 108 | check_github_token_access <- function(){ 109 | if(!has_github_token_access(silent = FALSE)){ 110 | usethis::ui_todo("Generate a new GitHub token with {usethis::ui_code('usethis::create_github_token()')}.") 111 | } 112 | invisible(has_github_token_access()) 113 | } 114 | 115 | #' @rdname check 116 | #' @export 117 | check_github_ssh <- function() { 118 | if (!has_github_ssh(silent = FALSE)) { 119 | if (has_github_ssh(force_logical = FALSE) == "recheck_authenticity") { 120 | usethis::ui_todo( 121 | "Run {usethis::ui_code('ssh -T git@github.com')} in a terminal. Answer yes if asked." 122 | ) 123 | msg_rerun("check_github_ssh()") 124 | } else if (!has_ssh()) { 125 | check_ssh() 126 | } else { 127 | usethis::ui_todo("Read:\n{usethis::ui_value('https://happygitwithr.com/ssh-keys.html')}.") 128 | } 129 | } 130 | invisible(has_github_ssh()) 131 | } 132 | 133 | #' @rdname check 134 | #' @export 135 | check_github <- function(auth_method = "token"){ 136 | stopifnot(auth_method %in% c("token", "ssh")) 137 | if (!has_n_check(has_git, check_git)) { 138 | msg_rerun("check_github()") 139 | return(FALSE) 140 | } else if (auth_method == "ssh" && !has_n_check(has_ssh, check_ssh)) { 141 | msg_rerun("check_github()") 142 | return(FALSE) 143 | } else if (auth_method == "ssh" && !has_n_check(has_github_ssh, check_github_ssh)) { 144 | msg_rerun("check_github()") 145 | return(FALSE) 146 | } else if (auth_method == "token" && !has_n_check(has_github_token, check_github_token)) { 147 | msg_rerun("check_github()") 148 | return(FALSE) 149 | } else if (auth_method == "token" && !has_n_check(has_github_token_access, check_github_token_access)) { 150 | msg_rerun("check_github()") 151 | } else { 152 | invisible(has_github(silent = FALSE)) 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /R/check_package.R: -------------------------------------------------------------------------------- 1 | #' Check if package exists 2 | #' 3 | #' @param pkg Which package are we talking about? 4 | #' @param install Should we install the package in case its missing? 5 | #' @param github A github username/package from which the package is installed. 6 | #' If NULL (the default) CRAN (or whatever repo) you have set is used. 7 | #' @family checkers 8 | #' @export 9 | 10 | check_package <- function(pkg, install = getOption("repro.install"), github = NULL){ 11 | check_package_factory(pkg, github)(install = install) 12 | } 13 | 14 | check_package_factory <- function(pkg, github = NULL) { 15 | function(install = getOption("repro.install")) { 16 | if (!has_factory_package(pkg)(silent = FALSE)) { 17 | if (install == "ask" && is.character(github)) { 18 | install <- 19 | !usethis::ui_nope( 20 | "Do you want to install the {usethis::ui_code(pkg)}-package from github.com/{github}?" 21 | ) 22 | } else if (install == "ask") { 23 | install <- 24 | !usethis::ui_nope("Do you want to install the {usethis::ui_code(pkg)}-package?") 25 | } 26 | if (install) { 27 | if (is.character(github) && 28 | check_package_factory("remotes", github = NULL)(install = install)) { 29 | options(repro.ssh = dangerous_succeeds(remotes::install_github)(github)) 30 | } else { 31 | options(repro.ssh = dangerous_succeeds(utils::install.packages)(pkg)) 32 | } 33 | msg_restart_r() 34 | msg_rerun( 35 | glue::glue("check_{pkg}()"), 36 | glue::glue(" to verify that {usethis::ui_code(pkg)} is installed.") 37 | ) 38 | } 39 | } 40 | invisible(has_factory_package(pkg)()) 41 | } 42 | } 43 | 44 | #' @rdname check 45 | #' @export 46 | check_renv <- check_package_factory("renv") 47 | 48 | #' @rdname check 49 | #' @export 50 | check_targets <- check_package_factory("targets", "wlandau/targets") 51 | 52 | #' @rdname check 53 | #' @export 54 | check_worcs <- check_package_factory("worcs", "cjvanlissa/worcs") 55 | -------------------------------------------------------------------------------- /R/docker.R: -------------------------------------------------------------------------------- 1 | #' Use Docker 2 | #' 3 | #' Add or modify the Dockerfile in the current project. 4 | #' 5 | #' @param rver Which r version to use, defaults to current version. 6 | #' @param stack Which stack to use, possible values are `c("r-ver", "rstudio", "tidyverse", "verse", "geospatial")`. 7 | #' @param date Which date should be used for package instalation, defaults to today. 8 | #' @param file Which file to save to 9 | #' @param open Open the newly created file for editing? Happens in RStudio, if applicable, or via utils::file.edit() otherwise. 10 | #' @name docker 11 | #' @export 12 | 13 | use_docker <- function(rver = NULL, stack = "verse", date = Sys.Date(), file = "Dockerfile", open = TRUE){ 14 | if (is.null(rver)) { 15 | rver <- glue::glue(R.version$major, ".", R.version$minor) 16 | } 17 | usethis::use_template( 18 | "Dockerfile", 19 | file, 20 | data = list(rver = rver, 21 | stack = stack, 22 | date = date), 23 | ignore = FALSE, 24 | open = open, 25 | package = "repro" 26 | ) 27 | } 28 | 29 | #' Add dependencies to Dockerfile 30 | #' 31 | #' Adds package dependencies as a new RUN statement to Dockerfile. 32 | #' Sorts packages first into source (cran & github) and then alphabetically. 33 | #' 34 | #' @param packages Which packages to add. 35 | #' @param github Are there github packages? 36 | #' @param strict Defaults to TRUE, force a specific version for github packages. 37 | #' @param file Where is the 'Dockerfile'? 38 | #' @param write Should the 'Dockerfile' be modified? 39 | #' @param open Should the file be opened? 40 | #' @param append Should the return value be appended to the 'Dockerfile'? 41 | #' @export 42 | 43 | use_docker_packages <- function(packages, github = NULL, strict = TRUE, file = "Dockerfile", write = TRUE, open = write, append = TRUE){ 44 | # github stuff has these symbols 45 | on_github <- packages[stringr::str_detect(packages, "[/|@]")] 46 | # everything else is assumed to be on cran 47 | on_cran <- packages[!(packages %in% on_github)] 48 | if(!isTRUE(github) & (length(on_github) > 0)){ 49 | usethis::ui_warn("Some packages seem to come from GitHub. 50 | Set {usethis::ui_code('github = TRUE')} to silence this warning.") 51 | } 52 | if(isTRUE(strict) & any(!stringr::str_detect(on_github, "@"))){ 53 | usethis::ui_stop("Some github packages are without fixed version. Use the following scheme: 54 | {usethis::ui_code('author/package@version')} 55 | version can be a git tag or hash or 56 | set {usethis::ui_code('strict = FALSE')} on your own risk.") 57 | } 58 | 59 | # sort alphabetically and remove duplicates 60 | on_github <- unique(on_github) 61 | on_github <- sort(on_github) 62 | on_cran <- unique(on_cran) 63 | on_cran <- sort(on_cran) 64 | 65 | # construct Dockerfile entries 66 | # and write them appended to Dockerfile 67 | to_write <- character() 68 | if(length(on_cran) > 0){ 69 | cran_entry <- docker_entry_install(on_cran, 70 | "install2.r", 71 | "--error --skipinstalled") 72 | to_write <- c(to_write, cran_entry) 73 | } 74 | if(length(on_github) > 0){ 75 | github_entry <- docker_entry_install(on_github, "installGithub.r") 76 | to_write <- c(to_write, github_entry) 77 | } 78 | docker_entry(to_write, file, write, open, append, quiet = TRUE) 79 | } 80 | 81 | use_docker_apt <- function(apt, update = TRUE, file = "Dockerfile", write = TRUE, open = write, append = TRUE){ 82 | if(length(apt) == 0L)return(NULL) 83 | to_write <- "RUN " 84 | if(update)to_write <- stringr::str_c(to_write, "apt-get update -y && ") 85 | to_write <- stringr::str_c(to_write, "apt-get install -y ") 86 | to_write <- stringr::str_c(to_write, stringr::str_c(apt, collapse = " ")) 87 | docker_entry(to_write, file, write, open, append, quiet = TRUE) 88 | } 89 | 90 | docker_entry <- function(entry, file = "Dockerfile", write, open, append, quiet = FALSE) { 91 | if (!fs::file_exists(file)) { 92 | usethis::ui_oops(glue::glue("There is no {usethis::ui_path(file)}!")) 93 | usethis::ui_todo( 94 | glue::glue( 95 | "Run {usethis::ui_code('use_docker()')} to create {usethis::ui_path(file)}." 96 | ) 97 | ) 98 | return(invisible(NULL)) 99 | } 100 | # read dockerfile 101 | path <- usethis::proj_path(file) 102 | dockerfile <- xfun::read_utf8(path) 103 | if(!quiet){ 104 | usethis::ui_done("Adding {usethis::ui_value(entry)} to {usethis::ui_path(file)}") 105 | } 106 | if(append)entry <- c(dockerfile, entry) 107 | if (write) { 108 | xfun::write_utf8(entry, path) 109 | if (open) { 110 | usethis::edit_file(path) 111 | } 112 | return(invisible(entry)) 113 | } else { 114 | return(entry) 115 | } 116 | } 117 | 118 | docker_entry_install <- function(packages, cmd, flags = NULL){ 119 | entry <- stringr::str_c("RUN", cmd, flags, "\\\ ", sep = " ") 120 | if(length(packages) == 1L){ 121 | entry <- c(entry, stringr::str_c(" ", packages)) 122 | } else { 123 | entry <- c(entry, 124 | stringr::str_c(" ", packages[-length(packages)], " \\\ "), 125 | stringr::str_c(" ", packages[length(packages)])) 126 | } 127 | entry 128 | } 129 | 130 | docker_get_install <- function(dockerfile){ 131 | starts <- stringr::str_detect(dockerfile, "^(RUN install)(.*)(\\.)[Rr](.*)$") 132 | possible_range <- c(rep(which(starts), each = 2L)[-1], length(dockerfile)) 133 | possible_list <- apply(matrix(possible_range, ncol = 2L), 1, function(x)list(x)) 134 | possible_pos <- lapply(possible_list, function(x)seq(x[[1]][1], x[[1]][2])) 135 | possible <- lapply(possible_pos, function(x)dockerfile[x]) 136 | pos_raw <- lapply(possible, function(x)which(stringr::str_detect(x, "^( )"))) 137 | out <- vector("list", length(pos_raw)) 138 | for(i in seq_along(pos_raw)){ 139 | out[[i]] <- c(possible[[i]][1], possible[[i]][pos_raw[[i]]]) 140 | } 141 | return(out) 142 | } 143 | 144 | docker_get_packages <- function(file = "Dockerfile"){ 145 | if (!fs::file_exists(file)) { 146 | usethis::ui_oops(glue::glue("There is no {usethis::ui_path(file)}!")) 147 | usethis::ui_todo( 148 | glue::glue( 149 | "Run {usethis::ui_code('use_docker()')} to create {usethis::ui_path(file)}." 150 | ) 151 | ) 152 | return(invisible(NULL)) 153 | }else{ 154 | dockerfile <- readLines(file) 155 | } 156 | entry <- docker_get_install(dockerfile) 157 | packages_raw <- lapply(entry, function(x)x[stringr::str_detect(x, "^( )")]) 158 | packages <- lapply(packages_raw, function(x)stringr::str_extract(x, "[a-zA-z]+")) 159 | packages_sorted <- sort(unique(unlist(packages))) 160 | return(packages_sorted) 161 | } 162 | 163 | dir2imagename <- function(dir){ 164 | dir <- basename(dir) 165 | stopifnot(length(dir) == 1L) 166 | dir <- stringr::str_extract_all(dir, "[A-z0-9]")[[1]] 167 | dir <- stringr::str_c(dir, collapse = "") 168 | dir <- stringr::str_to_lower(dir) 169 | dir <- stringr::str_remove(dir, "^[0-9]") 170 | dir 171 | } 172 | 173 | #' @name docker 174 | #' @export 175 | use_dockerignore <- function(file, open = TRUE){ 176 | if(missing(file) || isTRUE(file))file <- getOption("repro.dockerignore") 177 | usethis::use_template( 178 | "dockerignore", 179 | file, 180 | ignore = FALSE, 181 | open = open, 182 | package = "repro" 183 | ) 184 | } -------------------------------------------------------------------------------- /R/docker_windows_path.R: -------------------------------------------------------------------------------- 1 | #' Generate the weird format for docker on windows. 2 | #' @param path Some windows path. If NULL the current directory. 3 | #' @param todo Should an actionable advice be given. Defaults to TRUE. 4 | #' @export 5 | docker_windows_path <- function(path = NULL, todo = interactive()){ 6 | if(is.null(path))path <- usethis::proj_path() 7 | path <- stringr::str_split(path, ":")[[1]] 8 | if(length(path) != 2L)usethis::ui_stop("This does not seem to be a Windows path.") 9 | path[[1]] <- stringr::str_c("//", stringr::str_to_lower(path[[1]])) 10 | out <- stringr::str_c(path[[1]], path[[2]]) 11 | if(todo)usethis::ui_todo("Replace in {usethis::ui_value('Makefile')}:\n{usethis::ui_value('WINPATH = //c/Users/someuser/Documents/myproject/')}\nwith:\n{usethis::ui_value(stringr::str_c('WINPATH = ', out))}") 12 | out 13 | } 14 | -------------------------------------------------------------------------------- /R/gha.R: -------------------------------------------------------------------------------- 1 | #' Deal with templates that are themselves whisker templates. 2 | #' 3 | #' If a template is itself used again as a whisker template, we need some other escape mechanism. 4 | #' The `repro`-template than uses `[[]]` instead of `{{}}` which are than later reinstated. 5 | #' 6 | #' @param template [`usethis::use_template()`] 7 | #' @param save_as [`usethis::use_template()`] 8 | #' @param escape named vector, name is replacement (default curly), value is placeholder (default square) 9 | #' @param data [`usethis::use_template()`] 10 | #' @param ignore [`usethis::use_template()`] 11 | #' @param open [`usethis::use_template()`] 12 | #' @param package [`usethis::use_template()`] 13 | use_template_template <- function(template, save_as = template, escape = c(`\\[\\[` = "{{", `\\]\\]` = "}}"), data = list(), ignore = FALSE, open = FALSE, package = "repro"){ 14 | usethis::use_template(template = template, save_as = save_as, data = data, ignore = ignore, open = FALSE, package = package) 15 | location <- usethis::proj_path(save_as) 16 | intermediate <- xfun::read_utf8(location) 17 | out <- stringr::str_replace_all(intermediate, escape) 18 | xfun::write_utf8(out, location) 19 | if(open)usethis::edit_file(location) 20 | invisible() 21 | } 22 | 23 | #' Use GitHub Action to Build Dockerimage 24 | #' 25 | #' Add an standard actions that builds and publishes an Dockerimage from the `Dockerfile`. 26 | #' 27 | #' @param file Which file to save to. 28 | #' @param open Open the newly created file for editing? Happens in RStudio, if applicable, or via utils::file.edit() otherwise. 29 | #' @export 30 | 31 | use_gha_docker <- function(file = getOption("repro.gha.docker"), open = TRUE){ 32 | if(uses_docker()){ 33 | fs::dir_create(fs::path_dir(usethis::proj_path(file))) 34 | use_template_template( 35 | "push-container.yml", 36 | file, 37 | data = list(), 38 | ignore = FALSE, 39 | open = open, 40 | package = "repro" 41 | ) 42 | } else { 43 | invisible() 44 | } 45 | } 46 | 47 | 48 | #' Use GitHub Action to Publish Results 49 | #' 50 | #' Add an standard actions that builds the `publish`-target, and publishes the results on the `gh-pages` branch. 51 | #' Requires a Dockerimage published within the same GitHub repository. See [`use_gha_docker()`]. 52 | #' 53 | #' @param file Which file to save to. 54 | #' @param open Open the newly created file for editing? Happens in RStudio, if applicable, or via utils::file.edit() otherwise. 55 | #' @export 56 | 57 | use_gha_publish <- function(file = getOption("repro.gha.publish"), open = TRUE){ 58 | if(uses_gha_docker()){ 59 | fs::dir_create(fs::path_dir(usethis::proj_path(file))) 60 | use_template_template( 61 | "publish.yml", 62 | file, 63 | data = list(), 64 | ignore = FALSE, 65 | open = open, 66 | package = "repro" 67 | ) 68 | } else { 69 | invisible() 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /R/has.R: -------------------------------------------------------------------------------- 1 | option_is_na <- function(opt){ 2 | is.na(getOption(opt)) 3 | } 4 | option_exists <- function(opt){ 5 | !is.null(getOption(opt)) 6 | } 7 | 8 | dangerous <- function(func, condition = getOption("repro.pkgtest"), ...){ 9 | # while testing, functions which rely on the specific computer infrastructure 10 | # should not be called 11 | func_chr <- deparse(substitute(func)) 12 | condition_chr <- deparse(substitute(condition)) 13 | if(length(list(...)) != 0L)usethis::ui_stop("Do not pass additional args to dangerous. Pass them to the resulting function.") 14 | function(...){ 15 | # !isFALSE is most conservative, everything that is not FALSE triggers it 16 | if(!isFALSE(condition)){ 17 | usethis::ui_stop("{usethis::ui_code(condition_chr)} forbids the use of {usethis::ui_code(func_chr)}.") 18 | } else { 19 | return(do.call(func, list(...))) 20 | } 21 | } 22 | } 23 | 24 | dangerous_succeeds <- function(func, condition = getOption("repro.pkgtest"), ...) { 25 | fenced <- dangerous(func, condition) 26 | function(...) { 27 | # returns TRUE if the dangerous commands succeeds 28 | !inherits(try(do.call(fenced, list(...)), 29 | silent = TRUE), 30 | "try-error") 31 | } 32 | } 33 | 34 | has_n_check <- function(has, check){ 35 | # this function is useful if you want to verify that everything is ok 36 | # but only notify the user on failure 37 | if(!do.call(has, list()))do.call(check, list()) 38 | do.call(has, list()) 39 | } 40 | 41 | has_factory <- function(name, option, internal, msg = msg_installed){ 42 | # all has-functions are extremely similar 43 | # hence a function factory pattern is used to avoid redundant code 44 | function(silent = TRUE, force_logical = TRUE){ 45 | # test with internal function only when option is NA or not existing 46 | if(!option_exists(option) || option_is_na(option)){ 47 | # getOption("repro.pkgtest") is set to TRUE while testing 48 | to_set <- list(do.call(internal, list())) 49 | names(to_set) <- option 50 | options(to_set) 51 | } 52 | # message status of option 53 | if(!silent)do.call(msg, list(name, getOption(option))) 54 | # return status of option 55 | if(force_logical){ 56 | # can only be true/false 57 | return(isTRUE(getOption(option))) 58 | } else { 59 | return(getOption(option)) 60 | } 61 | } 62 | } 63 | 64 | has_make_ <- function(){ 65 | # if I can get a make version, make must be there 66 | # successfull bash commands return 0 67 | silent_command("make", "-v") == 0L 68 | } 69 | has_git_ <- function()silent_command("git", "--version") == 0L 70 | has_docker_ <- function()silent_command("docker", "-v") == 0L 71 | has_docker_running_ <- function()all(fs::file_exists("/.dockerenv")) 72 | has_choco_ <- function()silent_command("choco", "-v") == 0L 73 | has_brew_ <- function()silent_command("brew", "--version") == 0L 74 | has_ssh_ <- function(){ 75 | !inherits(try(credentials::ssh_read_key(), silent = TRUE) 76 | , 77 | "try-error") 78 | } 79 | has_github_token_ <- function()gh::gh_token() != "" 80 | has_gitub_token_access_ <- function(){ 81 | result <- tryCatch(gh::gh("/user"), error = function(e)e) 82 | if(inherits(result, "gh_response"))return(TRUE) 83 | if(inherits(result, "http_error_401"))return("bad_credentials") 84 | if(inherits(result, "rlib_error") && grepl("one of these forms", result$message))return("bad_format") 85 | else return(FALSE) 86 | } 87 | has_github_ssh_ <- function(){ 88 | temp <- tempfile() 89 | system2("ssh", "-T git@github.com", stdout = temp, stderr = temp) 90 | output <- readLines(temp) 91 | if(any(grepl("authenticity", output)))return("recheck_authenticity") 92 | if(any(grepl("success", output)))return(TRUE) 93 | else return(FALSE) 94 | } 95 | has_github_ <- function()has_git() && has_github_ssh() && has_github_token() && has_github_token_access() 96 | 97 | #' Check System Dependencies 98 | #' 99 | #' Corresponding functions to [`check`], but intended for programatic use. 100 | #' 101 | #' @param silent Should a message be printed that informs the user? 102 | #' @param force_logical Should the return value be passed through [`isTRUE`](base)? 103 | #' @name has 104 | #' @family checkers 105 | NULL 106 | 107 | #' @rdname has 108 | #' @export 109 | has_make <- has_factory("Make", "repro.make", dangerous(has_make_)) 110 | 111 | #' @rdname has 112 | #' @export 113 | has_git <- has_factory("Git", "repro.git", dangerous(has_git_)) 114 | 115 | #' @rdname has 116 | #' @export 117 | has_docker <- has_factory("Docker", "repro.docker", dangerous(has_docker_)) 118 | 119 | #' @rdname has 120 | #' @export 121 | has_docker_running <- has_factory("Docker", 122 | "repro.docker.running", 123 | dangerous(has_docker_running_), 124 | msg_docker_running) 125 | 126 | #' @rdname has 127 | #' @export 128 | has_choco <- has_factory("Chocolately", "repro.choco", dangerous(has_choco_)) 129 | 130 | #' @rdname has 131 | #' @export 132 | has_brew <- has_factory("Homebrew", "repro.brew", dangerous(has_brew_)) 133 | 134 | #' @rdname has 135 | #' @export 136 | has_ssh <- has_factory("SSH", "repro.ssh", dangerous(has_ssh_), msg_ssh_keys) 137 | 138 | #' @rdname has 139 | #' @export 140 | has_github_token <- has_factory("GitHub token", "repro.github.token", dangerous(has_github_token_), msg_github_token) 141 | 142 | #' @rdname has 143 | #' @export 144 | has_github_token_access <- has_factory("GitHub token access", "repro.github.token.access", dangerous(has_github_token_access_), msg_github_token_access) 145 | 146 | #' @rdname has 147 | #' @export 148 | has_github_ssh <- has_factory("GitHub ssh", "repro.github.ssh", dangerous(has_github_ssh_), msg_github_ssh) 149 | 150 | #' @rdname has 151 | #' @export 152 | has_github <- has_factory("GitHub", "repro.github", has_github_, msg_service) 153 | -------------------------------------------------------------------------------- /R/has_package.R: -------------------------------------------------------------------------------- 1 | #' Check if package exists 2 | #' 3 | #' 4 | #' @param pkg Which package are we talking about? 5 | #' @inheritParams has 6 | #' @family checkers 7 | #' @export 8 | has_package <- function(pkg, silent = TRUE, force_logical = TRUE){ 9 | has_factory_package(pkg)(silent = silent, force_logical = silent) 10 | } 11 | 12 | has_factory_package <- function(pkg){ 13 | has_factory(pkg, 14 | stringr::str_c("repro.", pkg), 15 | function()requireNamespace(pkg, quietly = TRUE)) 16 | } 17 | 18 | #' @rdname has 19 | #' @export 20 | has_renv <- has_factory_package("renv") 21 | 22 | #' @rdname has 23 | #' @export 24 | has_targets <- has_factory_package("targets") 25 | 26 | #' @rdname has 27 | #' @export 28 | has_worcs <- has_factory_package("worcs") 29 | 30 | #' @rdname has 31 | #' @export 32 | has_gert <- has_factory_package("gert") 33 | -------------------------------------------------------------------------------- /R/hash.R: -------------------------------------------------------------------------------- 1 | #' Report Current Hash 2 | #' 3 | #' Find out what the currently checked out commit is and report its respective 4 | #' hash. 5 | #' 6 | #' @param length The length to which the hash is cut. 7 | #' @param backend Can be either of `NULL`, "gert", or "git". If `NULL` Git is 8 | #' used with preference and `gert` as a fallback. 9 | #' @export 10 | 11 | current_hash <- function(length = 7L, backend = NULL) { 12 | if (is.null(backend)) { 13 | if (has_git()) 14 | backend <- "git" 15 | else if (has_gert()) 16 | backend <- "gert" 17 | else 18 | usethis::ui_stop("Neither Git nor the gert package detected.") 19 | } else { 20 | if (!isTRUE(backend %in% c("git", "gert"))) 21 | usethis::ui_stop("{usethis::ui_code('backend')} is neither \"git\" nor \"gert\".") 22 | } 23 | if (backend == "git") { 24 | hash <- 25 | suppressWarnings(system2( 26 | "git", 27 | c("rev-parse", "HEAD"), 28 | stdout = TRUE, 29 | stderr = TRUE 30 | )) 31 | if(isFALSE(is.null(attr(hash, "status"))))usethis::ui_stop("Maybe not a Git repository.") 32 | } else { 33 | hash <- gert::git_commit_id() 34 | } 35 | strtrim(hash, length) 36 | } 37 | -------------------------------------------------------------------------------- /R/make.R: -------------------------------------------------------------------------------- 1 | #' Use Make 2 | #' 3 | #' Add a (GNU-)Makefile(s) with special emphasis on the use of containers. 4 | #' @param file Path to the file that is to be created. 5 | #' @param docker If true or a path a setup is created that can partially send make commands to a Docker container. 6 | #' @param singularity If true or a path a setup is created that can partially send make commands to a Singularity container (which requires the Dockerimage) 7 | #' @param torque If true a or a path setup is created that can partially send make comands to a TORQUE job scheduler. Especially usefull in combination with a Singularity container. 8 | #' @param publish Should the `Makefile_publish` also be created? 9 | #' @param use_docker If true `use_docker()` is called. 10 | #' @param use_singularity If true `use_singularity()` is called. 11 | #' @param dockerignore If true a .dockerignore file is created. 12 | #' @param open Open the newly created file for editing? Happens in RStudio, if applicable, or via utils::file.edit() otherwise. 13 | #' @name make 14 | NULL 15 | 16 | #' @rdname make 17 | #' @export 18 | use_make <- function(docker = FALSE, publish = FALSE, singularity = FALSE, torque = FALSE, open = TRUE){ 19 | if(uses_make(silent = TRUE)){ 20 | return(uses_make()) 21 | } 22 | # start out with the simplist Makefile possible 23 | template_data <- list( 24 | project = dir2imagename(usethis::proj_path()), 25 | wrapper = FALSE, 26 | docker = FALSE, 27 | winpath = NULL, 28 | singularity = FALSE, 29 | torque = FALSE, 30 | rmds = FALSE, 31 | publish = FALSE, 32 | makefile_docker = getOption("repro.makefile.docker"), 33 | makefile_singularity = getOption("repro.makefile.singularity"), 34 | makefile_torque = getOption("repro.makefile.torque"), 35 | makefile_rmds = getOption("repro.makefile.rmds"), 36 | makefile_publish = getOption("repro.makefile.publish") 37 | ) 38 | # add publish to template 39 | if(isTRUE(publish) | is.character(publish)){ 40 | do.call(use_make_publish, list(file = publish)) 41 | } 42 | if(uses_make_publish(silent = TRUE)){ 43 | template_data$publish <- TRUE 44 | } 45 | # add Docker & Wrapper to template 46 | if(isTRUE(docker) | is.character(docker)){ 47 | do.call(use_make_docker, list(file = docker)) 48 | } else if(uses_docker(silent = TRUE)){ 49 | use_make_docker(use_docker = FALSE) 50 | } 51 | if(fs::file_exists(getOption("repro.makefile.docker"))){ 52 | template_data$wrapper <- TRUE 53 | template_data$docker <- TRUE 54 | template_data$winpath <- docker_windows_path( 55 | "C:/Users/someuser/Documents/myproject/", 56 | todo = FALSE 57 | ) 58 | } 59 | if(fs::file_exists(getOption("repro.makefile.rmds"))){ 60 | template_data$rmds <- TRUE 61 | } 62 | # add Singularity (and implicitly Docker) 63 | if(isTRUE(singularity) | is.character(singularity)){ 64 | do.call(use_make_singularity, list(file = singularity)) 65 | } 66 | if(fs::file_exists(getOption("repro.makefile.singularity"))){ 67 | if(!uses_docker(silent = TRUE))usethis::ui_stop("Singularity depends in this setup on Docker.\nSet {usethis::ui_code('docker = TRUE')} & {usethis::ui_code('singularity = TRUE')}") 68 | template_data$singularity <- TRUE 69 | } 70 | usethis::use_template( 71 | "Makefile.txt", 72 | "Makefile", 73 | data = template_data, 74 | ignore = FALSE, 75 | open = open, 76 | package = "repro" 77 | ) 78 | } 79 | 80 | #' @rdname make 81 | #' @export 82 | use_make_docker <- function(file, use_docker = TRUE, dockerignore = TRUE, open = FALSE){ 83 | if(missing(file))file <- getOption("repro.makefile.docker") 84 | if(isTRUE(file))file <- getOption("repro.makefile.docker") 85 | if(use_docker)use_docker() 86 | usethis::use_template( 87 | "Makefile_Docker", 88 | file, 89 | ignore = FALSE, 90 | open = open, 91 | package = "repro" 92 | ) 93 | if(dockerignore){ 94 | use_dockerignore() 95 | } 96 | } 97 | 98 | #' @rdname make 99 | #' @export 100 | use_make_singularity <- function(file, use_singularity = TRUE, open = FALSE){ 101 | if(missing(file))file <- getOption("repro.makefile.singularity") 102 | if(isTRUE(file))file <- getOption("repro.makefile.singularity") 103 | if(use_singularity)usethis::ui_oops("{usethis::ui_code('use_singularity')} is not implemented, yet.") 104 | usethis::use_template( 105 | "Makefile_Singularity", 106 | file, 107 | ignore = FALSE, 108 | open = FALSE, 109 | package = "repro" 110 | ) 111 | } 112 | 113 | #' @rdname make 114 | #' @export 115 | use_make_publish <- function(file, open = FALSE){ 116 | if(automate_dir()){ 117 | if(missing(file))file <- getOption("repro.makefile.publish") 118 | if(isTRUE(file))file <- getOption("repro.makefile.publish") 119 | usethis::use_template( 120 | "Makefile_publish", 121 | file, 122 | ignore = FALSE, 123 | open = FALSE, 124 | package = "repro" 125 | ) 126 | } 127 | } -------------------------------------------------------------------------------- /R/messages.R: -------------------------------------------------------------------------------- 1 | msg_restart <- function(consider = TRUE){ 2 | if(consider)usethis::ui_todo("Consider restarting your computer.") 3 | else usethis::ui_todo("Restart your computer.") 4 | } 5 | 6 | msg_restart_r <- function(consider = TRUE){ 7 | if(consider)usethis::ui_todo("Consider restarting R (command/ctrl + shift + F10).") 8 | else usethis::ui_todo("Restart R (command/ctrl + shift + F10).") 9 | } 10 | 11 | msg_installed <- function(what, installed = TRUE) { 12 | if (isTRUE(installed)) { 13 | usethis::ui_done("{what} is installed, don't worry.") 14 | } else if (isFALSE(installed)) { 15 | usethis::ui_oops("{what} is not installed.") 16 | } else { 17 | usethis::ui_oops("Something is wrong with {what}.") 18 | } 19 | return(invisible(installed)) 20 | } 21 | 22 | msg_ssh_keys <- function(what, installed){ 23 | if (isTRUE(installed))usethis::ui_done("You have SSH-keys, don't worry.") 24 | else usethis::ui_oops("You have no SSH-keys.") 25 | } 26 | 27 | msg_github_token <- function(what, installed){ 28 | if (isTRUE(installed))usethis::ui_done("You have a GitHub token, don't worry.") 29 | else usethis::ui_oops("You have no GitHub token.") 30 | } 31 | 32 | msg_github_token_access <- function(what, installed){ 33 | if (isTRUE(installed))usethis::ui_done("Your GitHub token grants access, don't worry.") 34 | else if(installed == "bad_credentials")usethis::ui_oops("Your GitHub token is not valid (anymore).") 35 | else if(installed == "bad_format")usethis::ui_oops("Your GitHub token has the wrong format.") 36 | else usethis::ui_oops("You currently have no access to GitHub.") 37 | } 38 | 39 | msg_github_ssh <- function(what, installed){ 40 | if (isTRUE(installed))usethis::ui_done("You have SSH access to GitHub, don't worry.") 41 | else if (isFALSE(installed))usethis::ui_oops("You have no access to GitHub.") 42 | else usethis::ui_oops("You currently have no access to GitHub.") 43 | } 44 | 45 | msg_docker_running <- function(what, installed){ 46 | if(isTRUE(installed))usethis::ui_done("You are inside a Docker container!") 47 | else usethis::ui_oops("You are *not* inside a Docker container!") 48 | } 49 | 50 | msg_service <- function(what, installed){ 51 | if(isTRUE(installed))usethis::ui_done("You and {what} are on good terms, don't worry.") 52 | else usethis::ui_oops("Your {what} configuration is slightly off.") 53 | } 54 | 55 | msg_install_with_choco <- function(what, how, todo, check = TRUE, windows_only = TRUE){ 56 | if(get_os() == "windows" || !windows_only){ 57 | usethis::ui_info("We recommend Chocolately for Windows users.") 58 | if(check) check_choco() 59 | if(!missing(how)){ 60 | usethis::ui_todo("Run {usethis::ui_code(how)} in an admin terminal to install {what}.") 61 | } 62 | if(!missing(todo))eval(todo) 63 | } 64 | return(invisible(NULL)) 65 | } 66 | 67 | msg_install_with_brew <- function(what, how, todo, check = TRUE, osx_only = TRUE){ 68 | if(get_os() == "osx" || !osx_only){ 69 | usethis::ui_info("We recommend Homebrew for OS X users.") 70 | if(check) check_brew() 71 | if(!missing(how)){ 72 | usethis::ui_todo("Run {usethis::ui_code(how)} in an admin terminal to install {what}.") 73 | } 74 | if(!missing(todo))eval(todo) 75 | } 76 | return(invisible(NULL)) 77 | } 78 | 79 | msg_install_with_apt <- function(what, how, todo, linux_only = TRUE){ 80 | if(get_os() == "linux" || !linux_only){ 81 | if(!missing(how)){ 82 | usethis::ui_info("Adapt to your native package manager (deb, rpm, brew, csw, eopkg).") 83 | usethis::ui_info("You may need admin rights, use {usethis::ui_code('sudo')} in this case.") 84 | usethis::ui_todo("Run {usethis::ui_code(how)} in a terminal to install {what}.") 85 | } 86 | if(!missing(todo))eval(todo) 87 | } 88 | return(invisible(NULL)) 89 | } 90 | 91 | msg_rerun <- function(what, why = "."){ 92 | why <- glue::glue(why) 93 | usethis::ui_todo("You may want to rerun {usethis::ui_code(what)}{why}") 94 | } 95 | 96 | msg_reproduce <- function(command){ 97 | usethis::ui_todo("To reproduce this project, run the following code in a terminal:") 98 | usethis::ui_code_block(command) 99 | } 100 | -------------------------------------------------------------------------------- /R/reproduce.R: -------------------------------------------------------------------------------- 1 | #' Find entrypoint for analysis and suggest how to reproduce it. 2 | #' 3 | #' `reproduce()` inspects the files of a project and suggest a way to reproduce the project. 4 | #' 5 | #' `reproduce()` walks through a list of functions that check for a specific entrypoint. 6 | #' As soon as a function returns a possible entrypoint the search stops. 7 | #' If no function is supplied the standard list of [reproduce_funs] is used. 8 | #' 9 | #' @param fun a function that inspects `dir` and advises on how to reproduce the analysis. Defaults to [reproduce_funs]. 10 | #' @param ... more functions like `fun`. 11 | #' @param path Were should I look for entrypoints? 12 | #' @param cache Default is `FALSE`. Some entrypoints have a cache, which you probably do not want to use in a reproduction. 13 | #' @param silent Should a message be presented? 14 | #' @return Returns invisibly the command users should use to reproduce. 15 | #' @seealso reproduce_funs 16 | #' @name reproduce 17 | #' @export 18 | reproduce <- function(fun, ..., path = ".", cache = FALSE, silent = FALSE){ 19 | dots <- list(...) 20 | if(missing(fun)) { 21 | if(!is.na(getOption("repro.reproduce.msg"))){ 22 | eval(getOption("repro.reproduce.msg")) 23 | return(invisible(TRUE)) 24 | } 25 | funs <- getOption("repro.reproduce.funs", repro::reproduce_funs) 26 | } else { 27 | funs <- c(list(fun), list(...)) 28 | } 29 | args <- rep(list(list(path = path, cache = cache)), length(funs)) 30 | walk_trough_funs(funs, args) 31 | } 32 | 33 | walk_trough_funs <- function(funs, args){ 34 | if(missing(args)) { 35 | # no args case 36 | for(f in funs) { 37 | condition <- isTRUE(do.call(f, list())) 38 | if(condition) break 39 | } 40 | } else { 41 | # at least one arg 42 | if(length(args) == 1L) { 43 | args <- rep(args, length(funs)) 44 | } 45 | stopifnot(length(funs) == length(args)) 46 | stopifnot(do.call(all, lapply(funs, is.function))) 47 | for(i in seq_along(funs)){ 48 | condition <- do.call(funs[[i]], args[[i]]) 49 | if(isTRUE(condition)) break 50 | } 51 | } 52 | out <- attr(condition, "command") 53 | return(invisible(out)) 54 | } 55 | 56 | dir_ls <- function(...){ 57 | dots <- list(...) 58 | stopifnot(any(c("regexp", "glob") %in% names(dots))) 59 | if(is.null(dots$all)) dots$all <- TRUE 60 | if(is.null(dots$type)) dots$type <- "file" 61 | if(is.null(dots$recurse)) dots$recurse <- TRUE 62 | do.call(fs::dir_ls, dots) 63 | } 64 | 65 | file_is_somewhere <- function(file, ...){ 66 | stopifnot(is.character(file), length(file) == 1) 67 | isTRUE(fs::file_exists(dir_ls(regexp = stringr::str_c(".*/", file, "$")))) 68 | } 69 | 70 | #' @rdname reproduce 71 | #' @export 72 | reproduce_make <- function(path, cache = FALSE, silent = FALSE){ 73 | candidates <- dir_ls(path = path, regexp = "^Makefile$") 74 | command <- "" 75 | if(verify_reproduce_candidates(candidates, silent = silent)){ 76 | command <- "make " 77 | if(isFALSE(cache))command <- stringr::str_c(command, "-B ") 78 | if(file_is_somewhere("Makefile_Docker")){ 79 | command <- stringr::str_c("make docker &&\n", command, "DOCKER=TRUE ") 80 | } 81 | msg_reproduce(command) 82 | } 83 | out <- verify_reproduce_candidates(path) 84 | attr(out, "command") <- command 85 | return(invisible(out)) 86 | } 87 | 88 | verify_reproduce_candidates <- function(path, silent = TRUE){ 89 | n <- length(path) 90 | exist <- fs::file_exists(path) 91 | if(n == 1L && isTRUE(exist))return(TRUE) 92 | else if(n == 0L)return(FALSE) 93 | else { 94 | path <- path[exist] 95 | if(!silent)usethis::ui_warn("Potential entrypoint candidates are: {usethis::ui_value(path)}") 96 | return(FALSE) 97 | } 98 | } 99 | 100 | #' A list of functions to detect entrypoints. 101 | #' 102 | #' At the moment only reproduce_make is available. 103 | #' 104 | #' @details `reproduce_make` detects make as an entrypoint if there is a Makefile at top level. 105 | #' If it does also encounter a Makefile_Docker somewhere it recognizes the different make instructions. 106 | #' @name reproduce_funs 107 | #' @seealso reproduce 108 | #' @export 109 | reproduce_funs <- list(reproduce_make) -------------------------------------------------------------------------------- /R/rerun.R: -------------------------------------------------------------------------------- 1 | #' Find entrypoint for analysis and suggest how to reproduce it. 2 | #' 3 | #' `rerun()` was renamed to [`reproduce()`]. `rerun()` is deprecated. 4 | #' 5 | #' @param ... passed to [`reproduce()`]. 6 | #' @seealso reproduce_funs 7 | #' @name rerun 8 | #' @export 9 | 10 | rerun <- function(...){ 11 | usethis::ui_warn("{usethis::ui_code('rerun()')} is deprecated/renamed.\nUse {usethis::ui_code('reproduce()')} instead.") 12 | reproduce(...) 13 | } -------------------------------------------------------------------------------- /R/template.R: -------------------------------------------------------------------------------- 1 | #' Create repro template 2 | #' 3 | #' Fills a newly created folder with examples of RMarkdown, scripts, and data, which work well with [repro::automate()]. 4 | #' 5 | #' @param path character specifieng target folder. Will be created if it doesn't exist. 6 | #' @param ... Passed down to the markdown template. 7 | #' @name template 8 | NULL 9 | 10 | #' @rdname template 11 | #' @export 12 | repro_template <- function(path, ...) { 13 | stopifnot(length(path) == 1L) 14 | # ensure path exists 15 | fs::dir_create(path, recurse = TRUE) 16 | usethis::proj_set(path, force = TRUE) 17 | usethis::use_template("markdown.Rmd", 18 | data = list(date = Sys.Date(), ...), 19 | package = "repro") 20 | fs::dir_create(usethis::proj_path("data")) 21 | fs::dir_create(usethis::proj_path("R")) 22 | utils::write.csv(get("mtcars"), usethis::proj_path("data", "mtcars.csv")) 23 | usethis::use_template("clean.R", 24 | "R/clean.R", 25 | package = "repro") 26 | } 27 | 28 | #' @rdname template 29 | #' @export 30 | use_repro_template <- repro_template -------------------------------------------------------------------------------- /R/uses.R: -------------------------------------------------------------------------------- 1 | #' Check Project Configuration 2 | #' 3 | #' Check if a project uses certain things, e.g. Make or Docker. 4 | #' 5 | #' @param silent Defaults to `false`. Should a message be printed that informs the user? 6 | #' @name uses 7 | #' @family checkers 8 | NULL 9 | 10 | file_indicates_use <- function(file, silent = TRUE, what, remedy){ 11 | if(!silent){ 12 | if(fs::file_exists(file))usethis::ui_done("You already use {what}.") 13 | else usethis::ui_oops("You do not use {what} at the momement. Use {usethis::ui_code(remedy)} to add it to your project.") 14 | } 15 | invisible(fs::file_exists(file)) 16 | } 17 | 18 | #' @rdname uses 19 | #' @export 20 | uses_make <- function(silent = FALSE) 21 | file_indicates_use("Makefile", silent, "Make", "use_make()") 22 | 23 | #' @rdname uses 24 | #' @export 25 | uses_docker <- function(silent = FALSE) 26 | file_indicates_use("Dockerfile", silent, "Docker", "use_docker()") 27 | 28 | #' @rdname uses 29 | #' @export 30 | uses_gha_docker <- function(silent = FALSE) 31 | file_indicates_use(getOption("repro.gha.docker"), silent, "GitHub Action Docker Push", "use_gha_docker()") 32 | 33 | #' @rdname uses 34 | #' @export 35 | uses_gha_publish <- function(silent = FALSE) 36 | file_indicates_use(getOption("repro.gha.publish"), silent, "GitHub Action Publish", "use_gha_publish()") 37 | 38 | #' @rdname uses 39 | #' @export 40 | uses_make_publish <- function(silent = FALSE) 41 | file_indicates_use(getOption("repro.makefile.publish"), silent, "Makefile_publish", "use_make_publish()") 42 | 43 | #' @rdname uses 44 | #' @export 45 | uses_make_rmds <- function(silent = FALSE) 46 | file_indicates_use(getOption("repro.makefile.rmds"), silent, "Makefile_Rmds", "automate_make()") -------------------------------------------------------------------------------- /R/yaml.R: -------------------------------------------------------------------------------- 1 | read_yaml <- function(path, ...){ 2 | x <- readLines(path) 3 | yaml_ind <- stringr::str_which(x, "^---[[:space:]]*") 4 | if(length(yaml_ind) == 0L)return(NULL) 5 | if(yaml_ind[[1]] > 2)return(NULL) 6 | stripped <- stringr::str_c(x[seq(yaml_ind[[1]] + 1, yaml_ind[[2]] - 1)], 7 | collapse = "\n") 8 | yaml <- yaml::read_yaml(text = stripped, ...) 9 | return(yaml) 10 | } 11 | 12 | yaml_repro <- function(yaml) { 13 | if ("repro" %in% names(yaml)) { 14 | out <- yaml$repro 15 | } else if ("repro" %in% names(yaml$params)) { 16 | out <- yaml$params$repro 17 | } else{ 18 | out <- list() 19 | } 20 | if ("output" %in% names(yaml)) { 21 | if (is.character(yaml$output)){ 22 | out$output <- yaml$output 23 | } else if (is.list(yaml$output)){ 24 | out$output <- names(yaml$output) 25 | } else { 26 | usethis::ui_stop("Output in one of the yamls is neither a list nor a character!")} 27 | } 28 | if ("bibliography" %in% names(yaml)) { 29 | out$bibliography <- yaml$bibliography 30 | } 31 | if (length(out) == 0L){ 32 | out <- NULL 33 | } 34 | if(length(out) == 0L)return(NULL) 35 | else return(out) 36 | } 37 | 38 | get_yamls <- function(path = ".", ...){ 39 | rmds <- fs::dir_ls(path, recurse = TRUE, glob = "*.Rmd") 40 | ymls <- lapply(rmds, read_yaml, ...) 41 | ymls <- lapply(ymls, yaml_repro) 42 | if(length(ymls) > 0)ymls[sapply(ymls, is.null)] <- NULL 43 | ymls <- lapply(names(ymls), function(x)c(list(file = x), ymls[[x]])) 44 | ymls 45 | } 46 | 47 | get_yamls_thing <- function(path = ".", what, ...){ 48 | ymls <- get_yamls(path, ...) 49 | things <- lapply(ymls, function(x)x[[what]]) 50 | things 51 | } 52 | 53 | yamls_packages <- function(path = ".", ...){ 54 | packages_list <- get_yamls_thing(path, "packages", ...) 55 | if(length(unlist(packages_list)) == 0L)return(NULL) 56 | package_lengths <- vapply(packages_list, function(x)length(x), FUN.VALUE = vector("integer", 1L)) 57 | packages <- unlist(packages_list[order(package_lengths, decreasing = TRUE)]) 58 | if(!is.character(packages))usethis::ui_oops("Something seems to be wrong with the package specification in one of the RMarkdowns.") 59 | return(packages) 60 | } 61 | 62 | yamls_apt <- function(path = ".", ...){ 63 | packages_list <- get_yamls_thing(path, "apt", ...) 64 | if(length(unlist(packages_list)) == 0L)return(NULL) 65 | package_lengths <- vapply(packages_list, function(x)length(x), FUN.VALUE = vector("integer", 1L)) 66 | packages <- unlist(packages_list[order(package_lengths, decreasing = TRUE)]) 67 | if(!is.character(packages))usethis::ui_oops("Something seems to be wrong with the apt specification in one of the RMarkdowns.") 68 | return(packages) 69 | } 70 | 71 | yaml_repro_current <- function() { 72 | if (length(yaml_repro(rmarkdown::metadata)) > 0L) { 73 | return(yaml_repro(rmarkdown::metadata)) 74 | } else{ 75 | if (exists("params")) 76 | yml <- get("params") 77 | else { 78 | if (requireNamespace("rstudioapi", quietly = TRUE)) { 79 | yml <- read_yaml(rstudioapi::getSourceEditorContext()$path) 80 | } else { 81 | usethis::ui_warn( 82 | "Can not find out where you currently are. Please install {usethis::ui_code('rstudioapi')}." 83 | ) 84 | return(NULL) 85 | } 86 | } 87 | } 88 | yaml_repro(yml) 89 | } 90 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | .onLoad <- function(...){ 2 | op <- options() 3 | op.repro <- list( 4 | repro.dir = ".repro", 5 | repro.dockerfile.base = "Dockerfile_base", 6 | repro.dockerfile.packages = "Dockerfile_packages", 7 | repro.dockerfile.apt = "Dockerfile_apt", 8 | repro.dockerfile.manual = "Dockerfile_manual", 9 | repro.dockerignore = ".dockerignore", 10 | repro.makefile.docker = "Makefile_Docker", 11 | repro.makefile.singularity = "Makefile_Singularity", 12 | repro.makefile.torque = "Makefile_TORQUE", 13 | repro.makefile.rmds = "Makefile_Rmds", 14 | repro.makefile.publish = "Makefile_publish", 15 | repro.docker = NA, 16 | repro.docker.running = NA, 17 | repro.make = NA, 18 | repro.git = NA, 19 | repro.choco = NA, 20 | repro.brew = NA, 21 | repro.ssh = NA, 22 | repro.renv = NA, 23 | repro.targets = NA, 24 | repro.worcs = NA, 25 | repro.os = NA, 26 | repro.github = NA, 27 | repro.github.ssh = NA, 28 | repro.github.token = NA, 29 | repro.github.token.access = NA, 30 | repro.gha.docker = ".github/workflows/push-container.yml", 31 | repro.gha.publish = ".github/workflows/publish.yml", 32 | repro.pkgtest = FALSE, 33 | repro.install = "ask", 34 | repro.reproduce.funs = reproduce_funs, 35 | repro.reproduce.msg = NA 36 | ) 37 | toset <- !(names(op.repro) %in% names(op)) 38 | if(any(toset)) options(op.repro[toset]) 39 | invisible() 40 | } 41 | 42 | .onAttach <- function(...){ 43 | packageStartupMessage( 44 | usethis::ui_info( 45 | "repro is BETA software! Please report any bugs: 46 | {usethis::ui_value('https://github.com/aaronpeikert/repro/issues')}") 47 | ) 48 | } 49 | 50 | get_os <- function(){ 51 | if(is.na(getOption("repro.os"))){ 52 | sysinf <- Sys.info() 53 | if(getOption("repro.pkgtest"))stop("Set a fake os while testing os dependend functions.", call. = FALSE) 54 | if (!is.null(sysinf)){ 55 | os <- sysinf['sysname'] 56 | if (os == 'Darwin') 57 | os <- "osx" 58 | } else { ## mystery machine 59 | os <- .Platform$OS.type 60 | if (grepl("^darwin", R.version$os)) 61 | os <- "osx" 62 | if (grepl("linux-gnu", R.version$os)) 63 | os <- "linux" 64 | } 65 | os <- tolower(os) 66 | options(repro.os = os) 67 | return(os) 68 | } else { 69 | return(getOption("repro.os")) 70 | } 71 | } 72 | 73 | silent_command <- function(...){ 74 | suppressMessages(suppressWarnings(system2(..., stdout = tempfile(), stderr = tempfile()))) 75 | } 76 | 77 | dir_name <- function(path){ 78 | out <- dirname(path) 79 | if(out == ".")return("") 80 | else stringr::str_c(out, "/") 81 | } -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "100%" 13 | ) 14 | ``` 15 | 16 | # repro 17 | 18 | 19 | [![R-CMD-check](https://github.com/aaronpeikert/repro/workflows/R-CMD-check/badge.svg)](https://github.com/aaronpeikert/repro/actions) 20 | [![Codecov test coverage](https://codecov.io/gh/aaronpeikert/repro/branch/main/graph/badge.svg)](https://codecov.io/gh/aaronpeikert/repro?branch=main) 21 | [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip) 22 | 23 | 24 | The goal of `repro` is to make the setup of reproducible workflows as easy as possible. To that end it builds upon the great [`usethis`-package](https://github.com/r-lib/usethis). `repro` currently undergoes significant changes to support more workflows than just the one proposed by [Peikert & Brandmaier (2019)](https://psyarxiv.com/8xzqy/). You may want to install the [`worcs`](https://github.com/cjvanlissa/worcs) package from CRAN for a user-friendly workflow that meets most requirements of reproducibility and open science. 25 | 26 | ## Installation 27 | 28 | You can install the latest version of repro from [GitHub](https://github.com/aaronpeikert/repro) with: 29 | 30 | ``` r 31 | if(!requireNamespace("remotes"))install.packages("remotes") 32 | remotes::install_github("aaronpeikert/repro") 33 | ``` 34 | 35 | ## Contribution 36 | 37 | I am more then happy if you want to contribute, but I ask you kindly to note that the 'repro' project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms. 38 | 39 | A contribution is especially welcome if it follows these principles: 40 | 41 | 1. The `repro` package aids the user setup reproducibility tools. 42 | 2. The reproduction itself must not require the `repro` package. 43 | 3. Do not suprisingly rely on the system or project state or change them. 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # repro 5 | 6 | 7 | 8 | [![R-CMD-check](https://github.com/aaronpeikert/repro/workflows/R-CMD-check/badge.svg)](https://github.com/aaronpeikert/repro/actions) 9 | [![Codecov test 10 | coverage](https://codecov.io/gh/aaronpeikert/repro/branch/main/graph/badge.svg)](https://codecov.io/gh/aaronpeikert/repro?branch=main) 11 | [![Project Status: WIP – Initial development is in progress, but there 12 | has not yet been a stable, usable release suitable for the 13 | public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip) 14 | 15 | 16 | The goal of `repro` is to make the setup of reproducible workflows as 17 | easy as possible. To that end it builds upon the great 18 | [`usethis`-package](https://github.com/r-lib/usethis). `repro` currently 19 | undergoes significant changes to support more workflows than just the 20 | one proposed by [Peikert & Brandmaier 21 | (2019)](https://psyarxiv.com/8xzqy/). You may want to install the 22 | [`worcs`](https://github.com/cjvanlissa/worcs) package from CRAN for a 23 | user-friendly workflow that meets most requirements of reproducibility 24 | and open science. 25 | 26 | ## Installation 27 | 28 | You can install the latest version of repro from 29 | [GitHub](https://github.com/aaronpeikert/repro) with: 30 | 31 | ``` r 32 | if(!requireNamespace("remotes"))install.packages("remotes") 33 | remotes::install_github("aaronpeikert/repro") 34 | ``` 35 | 36 | ## Contribution 37 | 38 | I am more then happy if you want to contribute, but I ask you kindly to 39 | note that the ‘repro’ project is released with a [Contributor Code of 40 | Conduct](CODE_OF_CONDUCT.md). By contributing to this project, you agree 41 | to abide by its terms. 42 | 43 | A contribution is especially welcome if it follows these principles: 44 | 45 | 1. The `repro` package aids the user setup reproducibility tools. 46 | 2. The reproduction itself must not require the `repro` package. 47 | 3. Do not suprisingly rely on the system or project state or change 48 | them. 49 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | patch: 10 | default: 11 | target: auto 12 | threshold: 1% 13 | -------------------------------------------------------------------------------- /inst/rstudio/templates/project/repro.dcf: -------------------------------------------------------------------------------- 1 | Binding: repro_template 2 | Title: Example Repro Template 3 | OpenFiles: markdown.Rmd 4 | 5 | Parameter: title 6 | Widget: TextInput 7 | Label: Title 8 | Default: An example 9 | Position: left 10 | 11 | Parameter: author 12 | Widget: TextInput 13 | Label: Author 14 | Default: Jane Doe 15 | Position: right -------------------------------------------------------------------------------- /inst/templates/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/{{{stack}}}:{{{rver}}} 2 | WORKDIR /home/rstudio 3 | RUN apt-get update -y && apt-get install -y rsync 4 | RUN tlmgr update --self && tlmgr install collection-latexrecommended 5 | -------------------------------------------------------------------------------- /inst/templates/Makefile.txt: -------------------------------------------------------------------------------- 1 | PROJECT := {{project}} 2 | WORKDIR := $(CURDIR) 3 | 4 | # list below your targets and their recipies 5 | all: 6 | 7 | {{#publish}} 8 | include {{makefile_publish}} 9 | 10 | {{/publish}} 11 | {{#wrapper}} 12 | ### Wrap Commands ### 13 | # if a command is to be send to another process e.g. a container/scheduler use: 14 | # $(RUN1) mycommand --myflag $(RUN2) 15 | RUN1 = $(QRUN1) $(SRUN) $(DRUN) 16 | RUN2 = $(QRUN2) 17 | 18 | {{/wrapper}} 19 | {{#rmds}} 20 | ### Rmd's ### 21 | include {{makefile_rmds}} 22 | 23 | {{/rmds}} 24 | {{#docker}} 25 | ### Docker ### 26 | # this is a workaround for windows users 27 | # please set WINDOWS=TRUE and adapt WINPATH if you are a windows user 28 | # note the unusual way to specify the path 29 | WINPATH = {{winpath}} 30 | include {{makefile_docker}} 31 | 32 | {{/docker}} 33 | {{#singularity}} 34 | ### Singularity ### 35 | include {{makefile_singularity}} 36 | 37 | {{/singularity}} 38 | {{#inspect}} 39 | # use `make print-anyvariable` to inspect the value of any variable 40 | print-%: ; @echo $* = $($*) 41 | 42 | {{/inspect}} 43 | -------------------------------------------------------------------------------- /inst/templates/Makefile_Docker: -------------------------------------------------------------------------------- 1 | ### Docker Options ### 2 | # --user indicates which user to emulate 3 | # -v which directory on the host should be accessable in the container 4 | # the last argument is the name of the container which is the project name 5 | DFLAGS = --rm $(DUSER) -v "$(DDIR)":"$(DHOME)" $(PROJECT) 6 | DCMD = run 7 | DHOME = /home/rstudio/ 8 | 9 | # docker for windows needs a pretty unusual path specification 10 | # which needs to be specified *manually* 11 | ifeq ($(WINDOWS),TRUE) 12 | ifndef WINDIR 13 | $(error WINDIR is not set) 14 | endif 15 | DDIR := $(WINDIR) 16 | # is meant to be empty 17 | UID := 18 | DUSER := 19 | else 20 | DDIR := $(CURDIR) 21 | UID = $(shell id -u) 22 | DUSER = --user $(UID) 23 | endif 24 | 25 | ### Docker Command ### 26 | 27 | ifeq ($(DOCKER),TRUE) 28 | DRUN := docker $(DCMD) $(DFLAGS) 29 | WORKDIR := $(DHOME) 30 | endif 31 | 32 | ### Docker Image ### 33 | 34 | docker: build 35 | build: Dockerfile 36 | docker build -t $(PROJECT) . 37 | rebuild: 38 | docker build --no-cache -t $(PROJECT) . 39 | save-docker: $(PROJECT).tar.gz 40 | $(PROJECT).tar.gz: 41 | docker save $(PROJECT):latest | gzip > $@ 42 | -------------------------------------------------------------------------------- /inst/templates/Makefile_Singularity: -------------------------------------------------------------------------------- 1 | ### Singularity Command ### 2 | 3 | ifeq ($(SINGULARITY),TRUE) 4 | SRUN := singularity $(SCMD) $(SFLAGS) 5 | current_dir=/home/rstudio 6 | endif 7 | 8 | ### Singularity Image ### 9 | 10 | singularity: $(PROJECT).sif 11 | 12 | $(PROJECT).sif: docker 13 | singularity build $@ docker-daemon://$(PROJECT):latest 14 | -------------------------------------------------------------------------------- /inst/templates/Makefile_TORQUE: -------------------------------------------------------------------------------- 1 | ### TORQUE Options ### 2 | WALLTIME = {walltime} 3 | MEMORY = 3gb 4 | QUEUE = default 5 | QFLAGS = -d $(CURDIR) -q $(QUEUE) -l nodes=1:ppn=$(NCORES) -l walltime=$(WALLTIME) -l mem=$(MEMORY) 6 | 7 | ### TORQUE Command ### 8 | ifeq ($(TORQUE),TRUE) 9 | QRUN1 := qsub $(QFLAGS) -F " 10 | QRUN2 := " forward.sh 11 | endif 12 | -------------------------------------------------------------------------------- /inst/templates/Makefile_publish: -------------------------------------------------------------------------------- 1 | publish/: 2 | mkdir -p $@ 3 | cp -r $^ $@ -------------------------------------------------------------------------------- /inst/templates/clean.R: -------------------------------------------------------------------------------- 1 | #----clean---- 2 | # remove polluters 3 | mycars <- subset(mycars, mpg > 15) 4 | -------------------------------------------------------------------------------- /inst/templates/dockerignore: -------------------------------------------------------------------------------- 1 | *.tar.gz 2 | -------------------------------------------------------------------------------- /inst/templates/forward.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # this script "forwards" everything by evalutaing its args as shell commands 3 | eval "$@" 4 | -------------------------------------------------------------------------------- /inst/templates/markdown.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: {{{title}}} 3 | author: {{{author}}} 4 | date: {{date}} 5 | repro: 6 | packages: 7 | - ggplot2 8 | - aaronpeikert/repro@adb5fa569 9 | scripts: 10 | - R/clean.R 11 | data: 12 | mycars: data/mtcars.csv 13 | output: html_document 14 | --- 15 | 16 | ```{r setup, echo=FALSE} 17 | knitr::opts_chunk$set(echo = TRUE) 18 | 19 | library(repro) 20 | # load packages from yaml header 21 | automate_load_packages() 22 | # include external scripts 23 | automate_load_scripts() 24 | # load data 'mycars' (ok it is mtcars...) 25 | mycars <- automate_load_data(mycars, read.csv, stringsAsFactors = FALSE) 26 | ``` 27 | 28 | ## Repro Package 29 | 30 | May I suggest to run `repro::automate()` now? This will create a `Dockerfile` & `Makefile` based on every RMarkdown file in this folder. 31 | The meta information that are provided in each RMarkdown (remember there are special yaml headers for repro) will be evaluted and adjustments will be made accordingly. 32 | 33 | If you are unsure whether or not you have `git` `make` & `docker` on your system, try running this in your R console: 34 | 35 | ```{r, eval=FALSE} 36 | check_git() 37 | check_make() 38 | check_docker() 39 | ``` 40 | 41 | ## Analysis 42 | 43 | ```{r clean} 44 | # see R/clean.R 45 | # this chunk (as long as it is empty, comments don't count) runs external 46 | # code from scripts listed in the YAML 47 | # see also https://yihui.org/knitr/demo/externalization/ 48 | ``` 49 | 50 | ```{r mpg} 51 | summary(mycars$mpg) 52 | ``` 53 | 54 | ## Including Plots 55 | 56 | ```{r plot, echo=FALSE} 57 | with(mycars, plot(mpg, hp)) 58 | ``` 59 | 60 | ## Including Fancy Plots 61 | 62 | ```{r fany-plot, echo=FALSE} 63 | ggplot(mycars, aes(mpg, hp)) + 64 | geom_point() + 65 | theme_minimal() + 66 | NULL 67 | ``` 68 | -------------------------------------------------------------------------------- /inst/templates/publish.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: main 4 | registry_package: 5 | types: [published, updated] 6 | workflow_dispatch: 7 | permissions: 8 | contents: write 9 | packages: write 10 | 11 | name: Render and publish 12 | 13 | jobs: 14 | imagename: 15 | runs-on: ubuntu-latest 16 | outputs: 17 | lowercase: $[[ steps.lowercase.outputs.test ]] 18 | steps: 19 | - 20 | name: Convert the repo name to lowercase. 21 | id: lowercase 22 | run: echo "::set-output name=test::$(echo $[[ github.repository ]] | tr '[:upper:]' '[:lower:]')" 23 | publish: 24 | runs-on: ubuntu-latest 25 | needs: imagename 26 | container: ghcr.io/$[[needs.imagename.outputs.lowercase]]:main 27 | steps: 28 | - 29 | name: Checkout repository 30 | uses: actions/checkout@v3 31 | - 32 | name: Make things to be published. 33 | run: | 34 | make publish/ 35 | - 36 | name: Publish 🚀 37 | # only publish when push to main 38 | if: github.event_name != 'pull_request' 39 | uses: JamesIves/github-pages-deploy-action@v4 40 | with: 41 | # The branch the action should deploy to. 42 | branch: gh-pages 43 | # The folder the action should deploy. 44 | folder: publish/ 45 | # Organizations require token of the bearer! 46 | token: $[[ secrets.GITHUB_TOKEN ]] 47 | -------------------------------------------------------------------------------- /inst/templates/push-container.yml: -------------------------------------------------------------------------------- 1 | name: Create and publish the required Docker image 2 | 3 | on: 4 | push: 5 | branches: ['main'] 6 | paths: 7 | - Dockerfile 8 | - .github/workflows/push-container.yml 9 | # to be able to trigger a manual build 10 | workflow_dispatch: 11 | 12 | env: 13 | REGISTRY: ghcr.io 14 | IMAGE_NAME: $[[ github.repository ]] 15 | 16 | jobs: 17 | build-and-push-image: 18 | runs-on: ubuntu-latest 19 | permissions: 20 | contents: read 21 | packages: write 22 | 23 | steps: 24 | - name: Checkout repository 25 | uses: actions/checkout@v3 26 | 27 | - name: Log in to the Container registry 28 | uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 29 | with: 30 | registry: $[[ env.REGISTRY ]] 31 | username: $[[ github.actor ]] 32 | password: $[[ secrets.GITHUB_TOKEN ]] 33 | 34 | - name: Extract metadata (tags, labels) for Docker 35 | id: meta 36 | uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 37 | with: 38 | images: $[[ env.REGISTRY ]]/$[[ env.IMAGE_NAME ]] 39 | 40 | - name: Build and push Docker image 41 | uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc 42 | with: 43 | context: . 44 | push: true 45 | tags: $[[ steps.meta.outputs.tags ]] 46 | labels: $[[ steps.meta.outputs.labels ]] -------------------------------------------------------------------------------- /man/automate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/automate.R 3 | \name{automate} 4 | \alias{automate} 5 | \alias{automate_make} 6 | \alias{automate_publish} 7 | \alias{automate_docker} 8 | \title{Automate the use of Docker & Make} 9 | \usage{ 10 | automate(path = ".") 11 | 12 | automate_make(path = ".") 13 | 14 | automate_publish(path = ".") 15 | 16 | automate_docker(path = ".") 17 | } 18 | \arguments{ 19 | \item{path}{Where should we look for RMarkdowns?} 20 | } 21 | \description{ 22 | \code{automate()} & friends use yaml metadata from RMarkdowns to create 23 | \code{Dockerfile}'s and \code{Makefile}'s. It should be clear which is created by 24 | \code{automate_docker()} & which by \code{automate_make()}. 25 | } 26 | \seealso{ 27 | \code{\link[=automate_load_packages]{automate_load_packages()}}, \code{\link[=automate_load_data]{automate_load_data()}}, \code{\link[=automate_load_scripts]{automate_load_scripts()}} 28 | } 29 | -------------------------------------------------------------------------------- /man/automate_load.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/automate.R 3 | \name{automate_load} 4 | \alias{automate_load} 5 | \alias{automate_load_packages} 6 | \alias{automate_load_scripts} 7 | \alias{automate_load_data} 8 | \title{Access repro YAML Metadata from within the document} 9 | \usage{ 10 | automate_load_packages() 11 | 12 | automate_load_scripts() 13 | 14 | automate_load_data(data, func, ...) 15 | } 16 | \arguments{ 17 | \item{data}{How is the entry in the YAML called? It will be the name of the object.} 18 | 19 | \item{func}{Which function should be used to read in the data? Its first argument must be the path to the file.} 20 | 21 | \item{...}{Further arguments supplied to \code{func}.} 22 | } 23 | \value{ 24 | \code{automate_load_packages()} & \code{automate_load_scripts()} do not return anything. \code{automate_load_data()} returns the data. 25 | } 26 | \description{ 27 | \itemize{ 28 | \item \code{automate_load_packages()} loads all packages listed in YAML via \code{library()} 29 | \item \code{automate_load_scripts()} registeres external scripts via \code{knitr::read_chunk()} 30 | \item \code{automate_load_data()} reads in the data from the yaml with abitrary functions 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /man/check.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/check.R, R/check_package.R 3 | \name{check} 4 | \alias{check} 5 | \alias{check_docker} 6 | \alias{check_make} 7 | \alias{check_git} 8 | \alias{check_brew} 9 | \alias{check_choco} 10 | \alias{check_ssh} 11 | \alias{check_github_token} 12 | \alias{check_github_token_access} 13 | \alias{check_github_ssh} 14 | \alias{check_github} 15 | \alias{check_renv} 16 | \alias{check_targets} 17 | \alias{check_worcs} 18 | \title{Check System Dependencies} 19 | \usage{ 20 | check_docker() 21 | 22 | check_make() 23 | 24 | check_git() 25 | 26 | check_brew() 27 | 28 | check_choco() 29 | 30 | check_ssh(install = getOption("repro.install")) 31 | 32 | check_github_token(install = getOption("repro.install")) 33 | 34 | check_github_token_access() 35 | 36 | check_github_ssh() 37 | 38 | check_github(auth_method = "token") 39 | 40 | check_renv(install = getOption("repro.install")) 41 | 42 | check_targets(install = getOption("repro.install")) 43 | 44 | check_worcs(install = getOption("repro.install")) 45 | } 46 | \arguments{ 47 | \item{install}{Should something be installed? Defaults to "ask", but can be TRUE/FALSE.} 48 | 49 | \item{auth_method}{How do you want to authenticate with GitHub? Either "token" (default) or "ssh".} 50 | } 51 | \description{ 52 | Check if a dependency is installed and if not it recommends how to install it 53 | depending on the operating system. Most importantly it checks for 54 | \code{git}, \code{make} & \code{docker}. And just for convenience of the installation it 55 | checks on OS X for \code{Homebrew} and on Windows for \code{Chocolately}. 56 | } 57 | \seealso{ 58 | Other checkers: 59 | \code{\link{check_package}()}, 60 | \code{\link{has_package}()}, 61 | \code{\link{has}}, 62 | \code{\link{uses}} 63 | } 64 | \concept{checkers} 65 | -------------------------------------------------------------------------------- /man/check_package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/check_package.R 3 | \name{check_package} 4 | \alias{check_package} 5 | \title{Check if package exists} 6 | \usage{ 7 | check_package(pkg, install = getOption("repro.install"), github = NULL) 8 | } 9 | \arguments{ 10 | \item{pkg}{Which package are we talking about?} 11 | 12 | \item{install}{Should we install the package in case its missing?} 13 | 14 | \item{github}{A github username/package from which the package is installed. 15 | If NULL (the default) CRAN (or whatever repo) you have set is used.} 16 | } 17 | \description{ 18 | Check if package exists 19 | } 20 | \seealso{ 21 | Other checkers: 22 | \code{\link{check}}, 23 | \code{\link{has_package}()}, 24 | \code{\link{has}}, 25 | \code{\link{uses}} 26 | } 27 | \concept{checkers} 28 | -------------------------------------------------------------------------------- /man/current_hash.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hash.R 3 | \name{current_hash} 4 | \alias{current_hash} 5 | \title{Report Current Hash} 6 | \usage{ 7 | current_hash(length = 7L, backend = NULL) 8 | } 9 | \arguments{ 10 | \item{length}{The length to which the hash is cut.} 11 | 12 | \item{backend}{Can be either of \code{NULL}, "gert", or "git". If \code{NULL} Git is 13 | used with preference and \code{gert} as a fallback.} 14 | } 15 | \description{ 16 | Find out what the currently checked out commit is and report its respective 17 | hash. 18 | } 19 | -------------------------------------------------------------------------------- /man/docker.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/docker.R 3 | \name{docker} 4 | \alias{docker} 5 | \alias{use_docker} 6 | \alias{use_dockerignore} 7 | \title{Use Docker} 8 | \usage{ 9 | use_docker( 10 | rver = NULL, 11 | stack = "verse", 12 | date = Sys.Date(), 13 | file = "Dockerfile", 14 | open = TRUE 15 | ) 16 | 17 | use_dockerignore(file, open = TRUE) 18 | } 19 | \arguments{ 20 | \item{rver}{Which r version to use, defaults to current version.} 21 | 22 | \item{stack}{Which stack to use, possible values are \code{c("r-ver", "rstudio", "tidyverse", "verse", "geospatial")}.} 23 | 24 | \item{date}{Which date should be used for package instalation, defaults to today.} 25 | 26 | \item{file}{Which file to save to} 27 | 28 | \item{open}{Open the newly created file for editing? Happens in RStudio, if applicable, or via utils::file.edit() otherwise.} 29 | } 30 | \description{ 31 | Add or modify the Dockerfile in the current project. 32 | } 33 | -------------------------------------------------------------------------------- /man/docker_windows_path.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/docker_windows_path.R 3 | \name{docker_windows_path} 4 | \alias{docker_windows_path} 5 | \title{Generate the weird format for docker on windows.} 6 | \usage{ 7 | docker_windows_path(path = NULL, todo = interactive()) 8 | } 9 | \arguments{ 10 | \item{path}{Some windows path. If NULL the current directory.} 11 | 12 | \item{todo}{Should an actionable advice be given. Defaults to TRUE.} 13 | } 14 | \description{ 15 | Generate the weird format for docker on windows. 16 | } 17 | -------------------------------------------------------------------------------- /man/has.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/has.R, R/has_package.R 3 | \name{has} 4 | \alias{has} 5 | \alias{has_make} 6 | \alias{has_git} 7 | \alias{has_docker} 8 | \alias{has_docker_running} 9 | \alias{has_choco} 10 | \alias{has_brew} 11 | \alias{has_ssh} 12 | \alias{has_github_token} 13 | \alias{has_github_token_access} 14 | \alias{has_github_ssh} 15 | \alias{has_github} 16 | \alias{has_renv} 17 | \alias{has_targets} 18 | \alias{has_worcs} 19 | \alias{has_gert} 20 | \title{Check System Dependencies} 21 | \usage{ 22 | has_make(silent = TRUE, force_logical = TRUE) 23 | 24 | has_git(silent = TRUE, force_logical = TRUE) 25 | 26 | has_docker(silent = TRUE, force_logical = TRUE) 27 | 28 | has_docker_running(silent = TRUE, force_logical = TRUE) 29 | 30 | has_choco(silent = TRUE, force_logical = TRUE) 31 | 32 | has_brew(silent = TRUE, force_logical = TRUE) 33 | 34 | has_ssh(silent = TRUE, force_logical = TRUE) 35 | 36 | has_github_token(silent = TRUE, force_logical = TRUE) 37 | 38 | has_github_token_access(silent = TRUE, force_logical = TRUE) 39 | 40 | has_github_ssh(silent = TRUE, force_logical = TRUE) 41 | 42 | has_github(silent = TRUE, force_logical = TRUE) 43 | 44 | has_renv(silent = TRUE, force_logical = TRUE) 45 | 46 | has_targets(silent = TRUE, force_logical = TRUE) 47 | 48 | has_worcs(silent = TRUE, force_logical = TRUE) 49 | 50 | has_gert(silent = TRUE, force_logical = TRUE) 51 | } 52 | \arguments{ 53 | \item{silent}{Should a message be printed that informs the user?} 54 | 55 | \item{force_logical}{Should the return value be passed through \href{base}{\code{isTRUE}}?} 56 | } 57 | \description{ 58 | Corresponding functions to \code{\link{check}}, but intended for programatic use. 59 | } 60 | \seealso{ 61 | Other checkers: 62 | \code{\link{check_package}()}, 63 | \code{\link{check}}, 64 | \code{\link{has_package}()}, 65 | \code{\link{uses}} 66 | } 67 | \concept{checkers} 68 | -------------------------------------------------------------------------------- /man/has_package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/has_package.R 3 | \name{has_package} 4 | \alias{has_package} 5 | \title{Check if package exists} 6 | \usage{ 7 | has_package(pkg, silent = TRUE, force_logical = TRUE) 8 | } 9 | \arguments{ 10 | \item{pkg}{Which package are we talking about?} 11 | 12 | \item{silent}{Should a message be printed that informs the user?} 13 | 14 | \item{force_logical}{Should the return value be passed through \href{base}{\code{isTRUE}}?} 15 | } 16 | \description{ 17 | Check if package exists 18 | } 19 | \seealso{ 20 | Other checkers: 21 | \code{\link{check_package}()}, 22 | \code{\link{check}}, 23 | \code{\link{has}}, 24 | \code{\link{uses}} 25 | } 26 | \concept{checkers} 27 | -------------------------------------------------------------------------------- /man/make.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/make.R 3 | \name{make} 4 | \alias{make} 5 | \alias{use_make} 6 | \alias{use_make_docker} 7 | \alias{use_make_singularity} 8 | \alias{use_make_publish} 9 | \title{Use Make} 10 | \usage{ 11 | use_make( 12 | docker = FALSE, 13 | publish = FALSE, 14 | singularity = FALSE, 15 | torque = FALSE, 16 | open = TRUE 17 | ) 18 | 19 | use_make_docker(file, use_docker = TRUE, dockerignore = TRUE, open = FALSE) 20 | 21 | use_make_singularity(file, use_singularity = TRUE, open = FALSE) 22 | 23 | use_make_publish(file, open = FALSE) 24 | } 25 | \arguments{ 26 | \item{docker}{If true or a path a setup is created that can partially send make commands to a Docker container.} 27 | 28 | \item{publish}{Should the \code{Makefile_publish} also be created?} 29 | 30 | \item{singularity}{If true or a path a setup is created that can partially send make commands to a Singularity container (which requires the Dockerimage)} 31 | 32 | \item{torque}{If true a or a path setup is created that can partially send make comands to a TORQUE job scheduler. Especially usefull in combination with a Singularity container.} 33 | 34 | \item{open}{Open the newly created file for editing? Happens in RStudio, if applicable, or via utils::file.edit() otherwise.} 35 | 36 | \item{file}{Path to the file that is to be created.} 37 | 38 | \item{use_docker}{If true \code{use_docker()} is called.} 39 | 40 | \item{dockerignore}{If true a .dockerignore file is created.} 41 | 42 | \item{use_singularity}{If true \code{use_singularity()} is called.} 43 | } 44 | \description{ 45 | Add a (GNU-)Makefile(s) with special emphasis on the use of containers. 46 | } 47 | -------------------------------------------------------------------------------- /man/reproduce.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reproduce.R 3 | \name{reproduce} 4 | \alias{reproduce} 5 | \alias{reproduce_make} 6 | \title{Find entrypoint for analysis and suggest how to reproduce it.} 7 | \usage{ 8 | reproduce(fun, ..., path = ".", cache = FALSE, silent = FALSE) 9 | 10 | reproduce_make(path, cache = FALSE, silent = FALSE) 11 | } 12 | \arguments{ 13 | \item{fun}{a function that inspects \code{dir} and advises on how to reproduce the analysis. Defaults to \link{reproduce_funs}.} 14 | 15 | \item{...}{more functions like \code{fun}.} 16 | 17 | \item{path}{Were should I look for entrypoints?} 18 | 19 | \item{cache}{Default is \code{FALSE}. Some entrypoints have a cache, which you probably do not want to use in a reproduction.} 20 | 21 | \item{silent}{Should a message be presented?} 22 | } 23 | \value{ 24 | Returns invisibly the command users should use to reproduce. 25 | } 26 | \description{ 27 | \code{reproduce()} inspects the files of a project and suggest a way to reproduce the project. 28 | } 29 | \details{ 30 | \code{reproduce()} walks through a list of functions that check for a specific entrypoint. 31 | As soon as a function returns a possible entrypoint the search stops. 32 | If no function is supplied the standard list of \link{reproduce_funs} is used. 33 | } 34 | \seealso{ 35 | reproduce_funs 36 | } 37 | -------------------------------------------------------------------------------- /man/reproduce_funs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reproduce.R 3 | \docType{data} 4 | \name{reproduce_funs} 5 | \alias{reproduce_funs} 6 | \title{A list of functions to detect entrypoints.} 7 | \format{ 8 | An object of class \code{list} of length 1. 9 | } 10 | \usage{ 11 | reproduce_funs 12 | } 13 | \description{ 14 | At the moment only reproduce_make is available. 15 | } 16 | \details{ 17 | \code{reproduce_make} detects make as an entrypoint if there is a Makefile at top level. 18 | If it does also encounter a Makefile_Docker somewhere it recognizes the different make instructions. 19 | } 20 | \seealso{ 21 | reproduce 22 | } 23 | \keyword{datasets} 24 | -------------------------------------------------------------------------------- /man/rerun.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rerun.R 3 | \name{rerun} 4 | \alias{rerun} 5 | \title{Find entrypoint for analysis and suggest how to reproduce it.} 6 | \usage{ 7 | rerun(...) 8 | } 9 | \arguments{ 10 | \item{...}{passed to \code{\link[=reproduce]{reproduce()}}.} 11 | } 12 | \description{ 13 | \code{rerun()} was renamed to \code{\link[=reproduce]{reproduce()}}. \code{rerun()} is deprecated. 14 | } 15 | \seealso{ 16 | reproduce_funs 17 | } 18 | -------------------------------------------------------------------------------- /man/template.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/template.R 3 | \name{template} 4 | \alias{template} 5 | \alias{repro_template} 6 | \alias{use_repro_template} 7 | \title{Create repro template} 8 | \usage{ 9 | repro_template(path, ...) 10 | 11 | use_repro_template(path, ...) 12 | } 13 | \arguments{ 14 | \item{path}{character specifieng target folder. Will be created if it doesn't exist.} 15 | 16 | \item{...}{Passed down to the markdown template.} 17 | } 18 | \description{ 19 | Fills a newly created folder with examples of RMarkdown, scripts, and data, which work well with \code{\link[=automate]{automate()}}. 20 | } 21 | -------------------------------------------------------------------------------- /man/use_docker_packages.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/docker.R 3 | \name{use_docker_packages} 4 | \alias{use_docker_packages} 5 | \title{Add dependencies to Dockerfile} 6 | \usage{ 7 | use_docker_packages( 8 | packages, 9 | github = NULL, 10 | strict = TRUE, 11 | file = "Dockerfile", 12 | write = TRUE, 13 | open = write, 14 | append = TRUE 15 | ) 16 | } 17 | \arguments{ 18 | \item{packages}{Which packages to add.} 19 | 20 | \item{github}{Are there github packages?} 21 | 22 | \item{strict}{Defaults to TRUE, force a specific version for github packages.} 23 | 24 | \item{file}{Where is the 'Dockerfile'?} 25 | 26 | \item{write}{Should the 'Dockerfile' be modified?} 27 | 28 | \item{open}{Should the file be opened?} 29 | 30 | \item{append}{Should the return value be appended to the 'Dockerfile'?} 31 | } 32 | \description{ 33 | Adds package dependencies as a new RUN statement to Dockerfile. 34 | Sorts packages first into source (cran & github) and then alphabetically. 35 | } 36 | -------------------------------------------------------------------------------- /man/use_gha_docker.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gha.R 3 | \name{use_gha_docker} 4 | \alias{use_gha_docker} 5 | \title{Use GitHub Action to Build Dockerimage} 6 | \usage{ 7 | use_gha_docker(file = getOption("repro.gha.docker"), open = TRUE) 8 | } 9 | \arguments{ 10 | \item{file}{Which file to save to.} 11 | 12 | \item{open}{Open the newly created file for editing? Happens in RStudio, if applicable, or via utils::file.edit() otherwise.} 13 | } 14 | \description{ 15 | Add an standard actions that builds and publishes an Dockerimage from the \code{Dockerfile}. 16 | } 17 | -------------------------------------------------------------------------------- /man/use_gha_publish.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gha.R 3 | \name{use_gha_publish} 4 | \alias{use_gha_publish} 5 | \title{Use GitHub Action to Publish Results} 6 | \usage{ 7 | use_gha_publish(file = getOption("repro.gha.publish"), open = TRUE) 8 | } 9 | \arguments{ 10 | \item{file}{Which file to save to.} 11 | 12 | \item{open}{Open the newly created file for editing? Happens in RStudio, if applicable, or via utils::file.edit() otherwise.} 13 | } 14 | \description{ 15 | Add an standard actions that builds the \code{publish}-target, and publishes the results on the \code{gh-pages} branch. 16 | Requires a Dockerimage published within the same GitHub repository. See \code{\link[=use_gha_docker]{use_gha_docker()}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/use_template_template.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/gha.R 3 | \name{use_template_template} 4 | \alias{use_template_template} 5 | \title{Deal with templates that are themselves whisker templates.} 6 | \usage{ 7 | use_template_template( 8 | template, 9 | save_as = template, 10 | escape = c(`\\\\[\\\\[` = "{{", `\\\\]\\\\]` = "}}"), 11 | data = list(), 12 | ignore = FALSE, 13 | open = FALSE, 14 | package = "repro" 15 | ) 16 | } 17 | \arguments{ 18 | \item{template}{\code{\link[usethis:use_template]{usethis::use_template()}}} 19 | 20 | \item{save_as}{\code{\link[usethis:use_template]{usethis::use_template()}}} 21 | 22 | \item{escape}{named vector, name is replacement (default curly), value is placeholder (default square)} 23 | 24 | \item{data}{\code{\link[usethis:use_template]{usethis::use_template()}}} 25 | 26 | \item{ignore}{\code{\link[usethis:use_template]{usethis::use_template()}}} 27 | 28 | \item{open}{\code{\link[usethis:use_template]{usethis::use_template()}}} 29 | 30 | \item{package}{\code{\link[usethis:use_template]{usethis::use_template()}}} 31 | } 32 | \description{ 33 | If a template is itself used again as a whisker template, we need some other escape mechanism. 34 | The \code{repro}-template than uses \verb{[[]]} instead of \code{{{}}} which are than later reinstated. 35 | } 36 | -------------------------------------------------------------------------------- /man/uses.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/uses.R 3 | \name{uses} 4 | \alias{uses} 5 | \alias{uses_make} 6 | \alias{uses_docker} 7 | \alias{uses_gha_docker} 8 | \alias{uses_gha_publish} 9 | \alias{uses_make_publish} 10 | \alias{uses_make_rmds} 11 | \title{Check Project Configuration} 12 | \usage{ 13 | uses_make(silent = FALSE) 14 | 15 | uses_docker(silent = FALSE) 16 | 17 | uses_gha_docker(silent = FALSE) 18 | 19 | uses_gha_publish(silent = FALSE) 20 | 21 | uses_make_publish(silent = FALSE) 22 | 23 | uses_make_rmds(silent = FALSE) 24 | } 25 | \arguments{ 26 | \item{silent}{Defaults to \code{false}. Should a message be printed that informs the user?} 27 | } 28 | \description{ 29 | Check if a project uses certain things, e.g. Make or Docker. 30 | } 31 | \seealso{ 32 | Other checkers: 33 | \code{\link{check_package}()}, 34 | \code{\link{check}}, 35 | \code{\link{has_package}()}, 36 | \code{\link{has}} 37 | } 38 | \concept{checkers} 39 | -------------------------------------------------------------------------------- /prep.R: -------------------------------------------------------------------------------- 1 | #### Instructions #### 2 | # Unfortunately you cannot run this script mindlessly and be fine. 3 | # It may take a moment or two, so make sure you have some time for this. 4 | # Read it carefully, execute line by line and see how your computer responds. 5 | # Any line that does not start with '#' is meant to run in R. 6 | # Be kind, most computers are pretty sensitive. 7 | 8 | #### R/RStudio #### 9 | # Have you updated your R/RStudio in the last year? 10 | # No -> Update!!! Both! 11 | # Not sure -> Update. Both. 12 | # Yes -> Updating is still a good idea. 13 | # I don't use RStudio -> Though not mandatory, it will make your life easier! 14 | # Links for your convenience: 15 | # https://cran.r-project.org 16 | # https://rstudio.com/products/rstudio/download/#download 17 | 18 | #### GitHub #### 19 | # Do you have a GitHub Account? 20 | # Yes -> Make sure you remember password and username. 21 | # No -> Visit https://github.com/join 22 | 23 | # Have you requested a researcher/student discount? 24 | # Not really needed, just nice to have. 25 | # Yes -> Cool. 26 | # No -> Visit https://education.github.com/benefits 27 | 28 | #### repro-package #### 29 | if(!requireNamespace("devtools"))install.packages("devtools") 30 | if(!requireNamespace("repro"))devtools::install_github("aaronpeikert/repro") 31 | 32 | #### Git/Make/Docker #### 33 | # follow instructions, rerun till you are told to not worry, then do not worry. 34 | repro::check_git() 35 | repro::check_make() 36 | repro::check_docker() 37 | 38 | #### Git Setup #### 39 | # Introduce yourself to Git. It's the polite thing to do. 40 | # Edit name and email. 41 | usethis::use_git_config(user.name = "Jane Doe", user.email = "jane@example.org") 42 | 43 | #### SSH Keys #### 44 | # We'll connect your computer/Git and GitHub in the workshop. 45 | # If you have a moment, skim over (or go ahead eager beaver try it yourself): 46 | # https://happygitwithr.com/ssh-keys.html 47 | 48 | #### Wifi #### 49 | # You'll need internet access at the location of the workshop. 50 | # Your best bet is to have a working eduroam configuration. 51 | # If you're not 100% sure you'll have internet, come early, we'll figure it out. 52 | 53 | #### This doesn't work #### 54 | # If you right now hate any of the following: 55 | # * me 56 | # * your computer 57 | # * yourself 58 | # * the world 59 | # Or it simply doesn't work: 60 | # It's okay, we all have been there. Keep calm, do these three things: 61 | # 1. raise an issue: https://github.com/aaronpeikert/repro/issues/new 62 | # 2. Come early to the workshop: 63 | # * We figure it out together. 64 | # * I'll usually be there about an hour early. 65 | # 3. Watch cute video on youtube: https://www.youtube.com/watch?v=GdP44iBIvck 66 | 67 | #### Looking forward to seeing you! #### 68 | -------------------------------------------------------------------------------- /repro.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 | StripTrailingWhitespace: Yes 16 | 17 | BuildType: Package 18 | PackageUseDevtools: Yes 19 | PackageInstallArgs: --no-multiarch --with-keep.source 20 | PackageRoxygenize: rd,collate,namespace 21 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(repro) 3 | 4 | test_check("repro") 5 | -------------------------------------------------------------------------------- /tests/testthat/helper.R: -------------------------------------------------------------------------------- 1 | expect_unicode_message <- function(object, match, label = NULL){ 2 | withr::with_options(c(crayon.enabled = FALSE), { 3 | act <- testthat:::quasi_capture(rlang::enquo(object), label, testthat::capture_messages) 4 | }) 5 | expect( 6 | any(stringr::str_detect(act$cap, match)), 7 | glue::glue("Nothing in: 8 | '{stringr::str_sub(act$cap)}' 9 | does not match: 10 | '{stringi::stri_unescape_unicode(match)}'.") 11 | ) 12 | invisible(act$cap) 13 | } 14 | expect_ok <- function(object){ 15 | expect_unicode_message(object, stringi::stri_escape_unicode(cli::symbol$tick)) 16 | } 17 | expect_oops <- function(object){ 18 | expect_unicode_message(object, stringi::stri_escape_unicode(cli::symbol$cross)) 19 | } 20 | -------------------------------------------------------------------------------- /tests/testthat/helper_testfiles.R: -------------------------------------------------------------------------------- 1 | test_rmd1 <- ' 2 | --- 3 | title: "Test" 4 | author: "Aaron Peikert" 5 | date: "1/13/2020" 6 | output: html_document 7 | repro: 8 | packages: 9 | - dplyr 10 | - usethis 11 | - anytime 12 | data: 13 | - iris.csv 14 | scripts: 15 | - load.R 16 | - clean.R 17 | --- 18 | 19 | ```{r setup, include=FALSE} 20 | knitr::opts_chunk$set(echo = TRUE) 21 | ``` 22 | 23 | ## R Markdown 24 | 25 | This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . 26 | 27 | ' 28 | 29 | test_rmd2 <- ' 30 | --- 31 | title: "Test2" 32 | author: "Aaron Peikert" 33 | date: "1/13/2020" 34 | output: html_document 35 | repro: 36 | packages: 37 | - lubridate 38 | - readr 39 | data: 40 | - mtcars.csv 41 | scripts: 42 | - analyze.R 43 | - plots.R 44 | --- 45 | 46 | ```{r setup, include=FALSE} 47 | knitr::opts_chunk$set(echo = TRUE) 48 | ``` 49 | 50 | ## R Markdown 51 | 52 | This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . 53 | 54 | ' 55 | 56 | test_rmd3 <- ' 57 | --- 58 | title: "Test2" 59 | author: "Aaron Peikert" 60 | date: "1/13/2020" 61 | output: html_document 62 | --- 63 | 64 | ```{r setup, include=FALSE} 65 | knitr::opts_chunk$set(echo = TRUE) 66 | ``` 67 | 68 | ## R Markdown 69 | 70 | This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . 71 | 72 | ' 73 | 74 | test_rmd4 <- ' 75 | --- 76 | title: "Test4" 77 | author: "Aaron Peikert" 78 | date: "1/13/2020" 79 | output: html_document 80 | bibliography: temp.bib 81 | repro: 82 | packages: 83 | - lubridate 84 | - readr 85 | data: 86 | - mtcars.csv 87 | scripts: 88 | - analyze.R 89 | - plots.R 90 | files: 91 | test.zip 92 | images: 93 | images/test.jpg 94 | --- 95 | 96 | ```{r setup, include=FALSE} 97 | knitr::opts_chunk$set(echo = TRUE) 98 | ``` 99 | 100 | ## R Markdown 101 | 102 | This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . 103 | 104 | ' 105 | 106 | dockerfile <- "FROM rocker/verse:3.6.1 107 | ARG BUILD_DATE=2020-01-20 108 | WORKDIR /home/rstudio 109 | RUN install2.r --error --skipinstalled \ 110 | anytime \ 111 | dplyr \ 112 | usethis 113 | RUN install2.r --error --skipinstalled \ 114 | anytime \ 115 | lubridate \ 116 | readr \ 117 | usethis 118 | " -------------------------------------------------------------------------------- /tests/testthat/helper_usethis.R: -------------------------------------------------------------------------------- 1 | # copied from usethis: 2 | # https://github.com/r-lib/usethis/blob/b2e894eb6d1d7f3312a783db3bb03a7cc309ba61/tests/testthat/helper.R 3 | library(usethis) 4 | library(fs) 5 | 6 | ## attempt to activate a project, which is nice during development 7 | tryCatch(usethis::proj_set("."), error = function(e) NULL) 8 | 9 | ## If session temp directory appears to be, or be within, a project, there 10 | ## will be large scale, spurious test failures. 11 | ## The IDE sometimes leaves .Rproj files behind in session temp directory or 12 | ## one of its parents. 13 | ## Delete such files manually. 14 | session_temp_proj <- usethis:::proj_find(path_temp()) 15 | if (!is.null(session_temp_proj)) { 16 | Rproj_files <- fs::dir_ls(session_temp_proj, glob = "*.Rproj") 17 | ui_line(c( 18 | "Rproj file(s) found at or above session temp dir:", 19 | paste0("* ", Rproj_files), 20 | "Expect this to cause spurious test failures." 21 | )) 22 | } 23 | 24 | ## putting `pattern` in the package or project name is part of our strategy for 25 | ## suspending the nested project check during testing 26 | pattern <- "aaa" 27 | 28 | scoped_temporary_package <- function(dir = fs::file_temp(pattern = pattern), 29 | env = parent.frame(), 30 | rstudio = FALSE) { 31 | scoped_temporary_thing(dir, env, rstudio, "package") 32 | } 33 | 34 | scoped_temporary_project <- function(dir = fs::file_temp(pattern = pattern), 35 | env = parent.frame(), 36 | rstudio = FALSE) { 37 | scoped_temporary_thing(dir, env, rstudio, "project") 38 | } 39 | 40 | scoped_temporary_thing <- function(dir = fs::file_temp(pattern = pattern), 41 | env = parent.frame(), 42 | rstudio = FALSE, 43 | thing = c("package", "project")) { 44 | thing <- match.arg(thing) 45 | if (fs::dir_exists(dir)) { 46 | ui_stop("Target {usethis::ui_code('dir')} {usethis::ui_path(dir)} already exists.") 47 | } 48 | 49 | old_project <- usethis:::proj$cur 50 | ## Can't schedule a deferred project reset if calling this from the R 51 | ## console, which is useful when developing tests 52 | if (identical(env, globalenv())) { 53 | usethis::ui_done("Switching to a temporary project!") 54 | if (!is.null(old_project)) { 55 | command <- paste0('proj_set(\"', old_project, '\")') 56 | usethis::ui_todo( 57 | "Restore current project with: {usethis::ui_code(command)}" 58 | ) 59 | } 60 | } else { 61 | withr::defer({ 62 | withr::with_options( 63 | list(usethis.quiet = TRUE), 64 | usethis::proj_set(old_project, force = TRUE) 65 | ) 66 | setwd(old_project) 67 | fs::dir_delete(dir) 68 | }, envir = env) 69 | } 70 | 71 | withr::local_options(list(usethis.quiet = TRUE)) 72 | switch( 73 | thing, 74 | package = usethis::create_package(dir, rstudio = rstudio, open = FALSE, 75 | check_name = FALSE), 76 | project = usethis::create_project(dir, rstudio = rstudio, open = FALSE) 77 | ) 78 | usethis::proj_set(dir) 79 | setwd(dir) 80 | invisible(dir) 81 | } 82 | 83 | test_mode <- function() { 84 | before <- Sys.getenv("TESTTHAT") 85 | after <- if (before == "true") "false" else "true" 86 | Sys.setenv(TESTTHAT = after) 87 | cat("TESTTHAT:", before, "-->", after, "\n") 88 | invisible() 89 | } 90 | 91 | skip_if_not_ci <- function() { 92 | ci <- any(toupper(Sys.getenv(c("TRAVIS", "APPVEYOR"))) == "TRUE") 93 | if (ci) { 94 | return(invisible(TRUE)) 95 | } 96 | skip("Not on Travis or Appveyor") 97 | } 98 | 99 | expect_usethis_error <- function(...) { 100 | expect_error(..., class = "usethis_error") 101 | } 102 | 103 | expect_error_free <- function(...) { 104 | expect_error(..., regexp = NA) 105 | } 106 | 107 | is_build_ignored <- function(pattern, ..., base_path = proj_get()) { 108 | lines <- readLines(path(base_path, ".Rbuildignore"), warn = FALSE) 109 | length(grep(pattern, x = lines, fixed = TRUE, ...)) > 0 110 | } 111 | 112 | test_file <- function(fname) testthat::test_path("ref", fname) 113 | 114 | expect_proj_file <- function(...) expect_true(fs::file_exists(usethis::proj_path(...))) 115 | expect_proj_dir <- function(...) expect_true(fs::dir_exists(usethis::proj_path(...))) 116 | 117 | ## use from testthat once > 2.0.0 is on CRAN 118 | skip_if_offline <- function(host = "r-project.org") { 119 | skip_if_not_installed("curl") 120 | has_internet <- !is.null(curl::nslookup(host, error = FALSE)) 121 | if (!has_internet) { 122 | skip("offline") 123 | } 124 | } -------------------------------------------------------------------------------- /tests/testthat/setup-opts.R: -------------------------------------------------------------------------------- 1 | options(repro.pkgtest = TRUE, 2 | repro.install = FALSE, 3 | repro.docker.running = FALSE) 4 | -------------------------------------------------------------------------------- /tests/testthat/teardown-opts.R: -------------------------------------------------------------------------------- 1 | options(repro.pkgtest = FALSE, 2 | repro.install = "ask") -------------------------------------------------------------------------------- /tests/testthat/test-automate.R: -------------------------------------------------------------------------------- 1 | context("Test automate stuff") 2 | test_that("docker automate works", { 3 | op <- options() 4 | scoped_temporary_project() 5 | cat(test_rmd1, file = "test.Rmd") 6 | fs::dir_create("test") 7 | cat(test_rmd2, file = "test/test2.Rmd") 8 | automate() 9 | expect_proj_dir(".repro") 10 | expect_proj_file(".repro", "Dockerfile_base") 11 | expect_proj_file(".repro", "Dockerfile_packages") 12 | expect_proj_file(".repro", "Dockerfile_manual") 13 | expect_proj_file(".repro", "Makefile_Docker") 14 | expect_proj_file("Dockerfile") 15 | expect_proj_file("Makefile") 16 | expect_proj_file(".dockerignore") 17 | options(op) 18 | }) 19 | 20 | test_that("the inference of the resulting file of an Rmd works", { 21 | expect_equal(get_output_file("test.Rmd", "html_document"), "test.html") 22 | expect_equal(get_output_file("test.Rmd", "pdf_document"), "test.pdf") 23 | expect_equal(get_output_file("test.Rmd", "slidy_presentation"), "test.html") 24 | expect_equal(get_output_file("test.Rmd", "rmarkdown::pdf_document"), "test.pdf") 25 | }) 26 | 27 | test_that("automate respects options", { 28 | opts <- options() 29 | scoped_temporary_project() 30 | cat(test_rmd1, file = "test.Rmd") 31 | fs::dir_create("test") 32 | cat(test_rmd2, file = "test/test2.Rmd") 33 | options(repro.dir = "somedir", 34 | repro.dockerfile.base = "base", 35 | repro.dockerfile.manual = "manual", 36 | repro.dockerfile.packages = "packages") 37 | automate_docker() 38 | expect_proj_dir("somedir") 39 | expect_proj_file("somedir", "base") 40 | expect_proj_file("somedir", "packages") 41 | expect_proj_file("somedir", "manual") 42 | options(opts) 43 | }) 44 | 45 | test_that("automate dir works", { 46 | op <- options() 47 | scoped_temporary_project() 48 | automate_dir() 49 | expect_proj_dir(".repro") 50 | options(op) 51 | }) 52 | 53 | test_that("automate doesn't fail when there is no RMD", { 54 | op <- options() 55 | scoped_temporary_project() 56 | automate() 57 | expect_proj_dir(".repro") 58 | expect_proj_file(".repro", "Dockerfile_base") 59 | expect_proj_file(".repro", "Dockerfile_packages") 60 | expect_proj_file(".repro", "Dockerfile_manual") 61 | expect_proj_file(".repro", "Makefile_Docker") 62 | expect_proj_file("Dockerfile") 63 | expect_proj_file("Makefile") 64 | options(op) 65 | }) 66 | 67 | test_that("automate doesn't fail when the RMD has no output", { 68 | opts <- options() 69 | scoped_temporary_project() 70 | test_rmd1_no_out <- strsplit(test_rmd1, "\n", fixed = TRUE)[[1]] 71 | 72 | test_rmd1_no_out <- test_rmd1_no_out[!grepl("output", test_rmd1_no_out)] 73 | cat(test_rmd1_no_out, file = "test.Rmd", sep = "\n") 74 | automate() 75 | expect_proj_dir(".repro") 76 | expect_proj_file(".repro", "Dockerfile_base") 77 | expect_proj_file(".repro", "Dockerfile_packages") 78 | expect_proj_file(".repro", "Dockerfile_manual") 79 | expect_proj_file(".repro", "Makefile_Docker") 80 | expect_proj_file(".repro", "Makefile_Rmds") 81 | expect_proj_file("Dockerfile") 82 | expect_proj_file("Makefile") 83 | options(opts) 84 | }) 85 | 86 | test_that("automate doesn't require scripts or data or packages", { 87 | opts <- options() 88 | dir <- scoped_temporary_project() 89 | cat(test_rmd3, file = "test.Rmd") 90 | automate() 91 | expect_proj_dir(".repro") 92 | expect_proj_file(".repro", "Dockerfile_base") 93 | expect_proj_file(".repro", "Dockerfile_packages") 94 | expect_proj_file(".repro", "Dockerfile_manual") 95 | expect_proj_file(".repro", "Makefile_Docker") 96 | expect_proj_file(".repro", "Makefile_Rmds") 97 | expect_proj_file("Dockerfile") 98 | expect_proj_file("Makefile") 99 | expect_equal(do.call(yaml_to_make, get_yamls(".")[[1]]), 100 | "test.html: test.Rmd\n\t$(RUN1) Rscript -e 'rmarkdown::render(\"$(WORKDIR)/$<\", \"all\")' $(RUN2)") 101 | makefile_rmds <- readLines(".repro/Makefile_Rmds") 102 | expect_identical(makefile_rmds[[1]], 103 | "test.html: test.Rmd") 104 | expect_identical(makefile_rmds[[2]], 105 | "\t$(RUN1) Rscript -e 'rmarkdown::render(\"$(WORKDIR)/$<\", \"all\")' $(RUN2)") 106 | options(opts) 107 | }) 108 | 109 | test_that("automate identifies other dependencies like bibliography etc.", { 110 | opts <- options() 111 | dir <- scoped_temporary_project() 112 | cat(test_rmd4, file = "test.Rmd") 113 | automate() 114 | expect_equal(do.call(yaml_to_make, get_yamls(".")[[1]]), 115 | "test.html: test.Rmd mtcars.csv analyze.R plots.R temp.bib images/test.jpg test.zip\n\t$(RUN1) Rscript -e 'rmarkdown::render(\"$(WORKDIR)/$<\", \"all\")' $(RUN2)") 116 | makefile_rmds <- readLines(".repro/Makefile_Rmds") 117 | expect_identical(makefile_rmds[[1]], 118 | "test.html: test.Rmd mtcars.csv analyze.R plots.R temp.bib images/test.jpg test.zip") 119 | expect_identical(makefile_rmds[[2]], 120 | "\t$(RUN1) Rscript -e 'rmarkdown::render(\"$(WORKDIR)/$<\", \"all\")' $(RUN2)") 121 | options(opts) 122 | }) 123 | -------------------------------------------------------------------------------- /tests/testthat/test-check.R: -------------------------------------------------------------------------------- 1 | context("Test the different checking functions.") 2 | 3 | test_that("options set to TRUE are recognized.", { 4 | withr::with_options( 5 | list( 6 | repro.docker = TRUE, 7 | repro.make = TRUE, 8 | repro.git = TRUE, 9 | repro.choco = TRUE, 10 | repro.brew = TRUE, 11 | repro.renv = TRUE, 12 | repro.targets = TRUE, 13 | repro.worcs = TRUE 14 | ), 15 | { 16 | expect_ok(check_docker()) 17 | expect_ok(check_make()) 18 | expect_ok(check_git()) 19 | expect_ok(check_choco()) 20 | expect_ok(check_brew()) 21 | expect_ok(check_renv()) 22 | expect_ok(check_targets()) 23 | expect_ok(check_worcs()) 24 | 25 | expect_true(check_docker()) 26 | expect_true(check_make()) 27 | expect_true(check_git()) 28 | expect_true(check_choco()) 29 | expect_true(check_brew()) 30 | expect_true(check_renv()) 31 | expect_true(check_targets()) 32 | expect_true(check_worcs()) 33 | }) 34 | }) 35 | 36 | test_that("options set to FALSE are recognized.", { 37 | withr::with_options( 38 | list( 39 | repro.docker = FALSE, 40 | repro.make = FALSE, 41 | repro.git = FALSE, 42 | repro.choco = FALSE, 43 | repro.brew = FALSE, 44 | repro.renv = FALSE, 45 | repro.targets = FALSE, 46 | repro.worcs = FALSE, 47 | repro.os = "linux" 48 | ), 49 | { 50 | expect_oops(check_docker()) 51 | expect_oops(check_make()) 52 | expect_oops(check_git()) 53 | expect_oops(check_choco()) 54 | expect_oops(check_brew()) 55 | expect_oops(check_renv()) 56 | expect_oops(check_targets()) 57 | expect_oops(check_worcs()) 58 | 59 | expect_false(check_docker()) 60 | expect_false(check_make()) 61 | expect_false(check_git()) 62 | expect_false(check_choco()) 63 | expect_false(check_brew()) 64 | expect_false(check_renv()) 65 | expect_false(check_targets()) 66 | expect_false(check_worcs()) 67 | }) 68 | }) 69 | 70 | test_that("the correct instalation hint for Windows is given.", { 71 | withr::with_options( 72 | list( 73 | repro.docker = FALSE, 74 | repro.make = FALSE, 75 | repro.git = FALSE, 76 | repro.choco = FALSE, 77 | repro.os = "windows" 78 | ), 79 | { 80 | testthat::expect_message(check_docker(), "windows", ignore.case = TRUE) 81 | testthat::expect_message(check_docker(), "choco install", ignore.case = TRUE) 82 | testthat::expect_message(check_docker(), "chocolately", ignore.case = TRUE) 83 | testthat::expect_message(check_docker(), "docker", ignore.case = TRUE) 84 | 85 | testthat::expect_message(check_make(), "windows", ignore.case = TRUE) 86 | testthat::expect_message(check_make(), "choco install", ignore.case = TRUE) 87 | testthat::expect_message(check_make(), "chocolately", ignore.case = TRUE) 88 | testthat::expect_message(check_make(), "make", ignore.case = TRUE) 89 | 90 | testthat::expect_message(check_git(), "windows", ignore.case = TRUE) 91 | testthat::expect_message(check_git(), "choco install", ignore.case = TRUE) 92 | testthat::expect_message(check_git(), "chocolately", ignore.case = TRUE) 93 | testthat::expect_message(check_git(), "git", ignore.case = TRUE) 94 | 95 | testthat::expect_message(check_choco(), "choco", ignore.case = TRUE) 96 | } 97 | ) 98 | }) 99 | 100 | test_that("the correct instalation hint for OS X is given.", { 101 | withr::with_options( 102 | list( 103 | repro.docker = FALSE, 104 | repro.make = FALSE, 105 | repro.git = FALSE, 106 | repro.brew = FALSE, 107 | repro.os = "osx" 108 | ), 109 | { 110 | testthat::expect_message(check_docker(), "os x", ignore.case = TRUE) 111 | testthat::expect_message(check_docker(), "brew", ignore.case = TRUE) 112 | testthat::expect_message(check_docker(), "install", ignore.case = TRUE) 113 | testthat::expect_message(check_docker(), "docker", ignore.case = TRUE) 114 | testthat::expect_message(check_docker(), "--cask", ignore.case = TRUE) 115 | 116 | 117 | 118 | testthat::expect_message(check_git(), "os x", ignore.case = TRUE) 119 | testthat::expect_message(check_git(), "brew", ignore.case = TRUE) 120 | testthat::expect_message(check_git(), "install", ignore.case = TRUE) 121 | testthat::expect_message(check_git(), "git", ignore.case = TRUE) 122 | 123 | testthat::expect_message(check_make(), "os x", ignore.case = TRUE) 124 | testthat::expect_message(check_make(), "brew", ignore.case = TRUE) 125 | testthat::expect_message(check_make(), "install", ignore.case = TRUE) 126 | testthat::expect_message(check_make(), "make", ignore.case = TRUE) 127 | 128 | testthat::expect_message(check_brew(), "brew", ignore.case = TRUE) 129 | }) 130 | }) 131 | 132 | test_that("the correct instalation hint for linux is given.", { 133 | withr::with_options(list( 134 | repro.docker = FALSE, 135 | repro.make = FALSE, 136 | repro.git = FALSE, 137 | repro.os = "linux" 138 | ), 139 | { 140 | testthat::expect_message(check_docker(), "package manager", ignore.case = TRUE) 141 | testthat::expect_message(check_docker(), "docker", ignore.case = TRUE) 142 | 143 | testthat::expect_message(check_git(), "package manager", ignore.case = TRUE) 144 | testthat::expect_message(check_git(), "git", ignore.case = TRUE) 145 | 146 | testthat::expect_message(check_make(), "package manager", ignore.case = TRUE) 147 | testthat::expect_message(check_make(), "make", ignore.case = TRUE) 148 | }) 149 | }) 150 | 151 | test_that("forbidden function raise an error", { 152 | hello <- function()cat("Hello") 153 | dangerous_hello <- dangerous(hello, getOption("repro.pkgtest")) 154 | expect_usethis_error(dangerous_hello()) 155 | expect_usethis_error(has_git()) 156 | }) 157 | 158 | test_that("github function recognize options set to FALSE", { 159 | withr::with_options(list( 160 | repro.git = FALSE, 161 | repro.ssh = FALSE, 162 | repro.github.ssh = FALSE, 163 | repro.github.token = FALSE, 164 | repro.github.token.access = FALSE, 165 | repro.os = "linux"), { 166 | expect_false(check_ssh(install = FALSE)) 167 | expect_false(check_github_ssh()) 168 | expect_false(check_github_token(install = FALSE)) 169 | expect_false(check_github_token_access()) 170 | expect_false(check_github()) 171 | 172 | expect_oops(check_ssh(install = FALSE)) 173 | expect_oops(check_github_ssh()) 174 | expect_oops(check_github_token(install = FALSE)) 175 | expect_oops(check_github()) 176 | }) 177 | }) 178 | 179 | test_that("github function recognize options set to TRUE", { 180 | withr::with_options(list( 181 | repro.git = TRUE, 182 | repro.ssh = TRUE, 183 | repro.github.ssh = TRUE, 184 | repro.github.token = TRUE, 185 | repro.github.token.access = TRUE, 186 | repro.os = "linux"), { 187 | expect_true(check_ssh()) 188 | expect_true(check_github_ssh()) 189 | expect_true(check_github_token()) 190 | expect_true(check_github_token_access()) 191 | expect_true(check_github()) 192 | 193 | expect_ok(check_ssh()) 194 | expect_ok(check_github_ssh()) 195 | expect_ok(check_github_token()) 196 | expect_ok(check_github()) 197 | }) 198 | }) 199 | 200 | test_that("github function works token only", { 201 | withr::with_options(list( 202 | repro.git = TRUE, 203 | repro.ssh = FALSE, 204 | repro.github.ssh = FALSE, 205 | repro.github.token = TRUE, 206 | repro.github.token.access = TRUE, 207 | repro.os = "linux"), { 208 | expect_false(check_ssh()) 209 | expect_false(check_github_ssh()) 210 | expect_true(check_github_token()) 211 | expect_true(check_github()) 212 | 213 | expect_oops(check_ssh()) 214 | expect_oops(check_github_ssh()) 215 | expect_ok(check_github_token()) 216 | expect_ok(check_github()) 217 | }) 218 | }) 219 | 220 | test_that("github function works ssh only", { 221 | withr::with_options(list( 222 | repro.git = TRUE, 223 | repro.ssh = TRUE, 224 | repro.github.ssh = TRUE, 225 | repro.github.token = FALSE, 226 | repro.github.token.access = FALSE, 227 | repro.os = "linux"), { 228 | expect_true(check_ssh()) 229 | expect_true(check_github_ssh()) 230 | expect_false(check_github_token()) 231 | expect_true(check_github(auth_method = "ssh")) 232 | 233 | expect_ok(check_ssh()) 234 | expect_ok(check_github_ssh()) 235 | expect_oops(check_github_token()) 236 | expect_ok(check_github(auth_method = "ssh")) 237 | }) 238 | }) 239 | 240 | test_that("check functions return invisibly", { 241 | withr::with_options( 242 | list( 243 | repro.docker = TRUE, 244 | repro.make = TRUE, 245 | repro.git = TRUE, 246 | repro.choco = TRUE, 247 | repro.brew = TRUE, 248 | repro.ssh = TRUE, 249 | repro.github.ssh = TRUE, 250 | repro.github.token = TRUE, 251 | repro.github.token.access = TRUE, 252 | repro.os = "linux", 253 | repro.renv = TRUE, 254 | repro.targets = TRUE, 255 | repro.worcs = TRUE 256 | ), 257 | { 258 | check_funs <- stringr::str_subset(ls("package:repro"), "^check_") 259 | check_funs <- check_funs[!stringr::str_detect(check_funs, "^check_package")] 260 | lapply(check_funs, function(x)eval(bquote(expect_invisible(do.call(.(x), list()))))) 261 | }) 262 | }) 263 | -------------------------------------------------------------------------------- /tests/testthat/test-docker.R: -------------------------------------------------------------------------------- 1 | context("Test docker or Dockerfile related function.") 2 | 3 | test_that("use_docker creates a Dockerfile",{ 4 | scoped_temporary_project() 5 | use_docker() 6 | expect_proj_file("Dockerfile") 7 | }) 8 | 9 | test_that("use_docker_packages fails if there is no Dockerfile",{ 10 | scoped_temporary_project() 11 | expect_oops(use_docker_packages("here")) 12 | }) 13 | 14 | test_that("use_docker_packages warns about github packages",{ 15 | scoped_temporary_project() 16 | use_docker() 17 | # should warn about no github=TRUE 18 | expect_warning(use_docker_packages("r-lib/usethis@b2e894e", open = FALSE), 19 | "github = TRUE") 20 | # should warn about missing fixed version 21 | expect_error( 22 | use_docker_packages("r-lib/usethis", 23 | github = TRUE, 24 | open = FALSE), 25 | "fixed version", 26 | class = "usethis_error" 27 | ) 28 | # shouldn't warn about anything 29 | expect_warning(use_docker_packages("r-lib/usethis@b2e894e", 30 | github = TRUE, 31 | open = FALSE), 32 | NA) 33 | expect_warning(use_docker_packages("usethis", 34 | github = TRUE, 35 | open = FALSE), 36 | NA) 37 | }) 38 | 39 | test_that("docker_entry_install returns only characters", { 40 | expect_length(docker_entry_install("test", 41 | "installGithub.r"), 2L) 42 | 43 | expect_length(docker_entry_install(c("test", "another_test"), 44 | "installGithub.r"), 3L) 45 | 46 | expect_identical(docker_entry_install("test", 47 | "installGithub.r"), 48 | c("RUN installGithub.r \\ ", " test")) 49 | 50 | expect_identical(docker_entry_install(c("test", "another_test"), 51 | "installGithub.r"), 52 | c("RUN installGithub.r \\ ", " test \\ ", " another_test")) 53 | }) 54 | 55 | test_that("use_docker_packages actually adds them to the Dockerfile", { 56 | scoped_temporary_package() 57 | use_docker() 58 | use_docker_packages(c("test1", "test2")) 59 | dockerfile <- readLines("Dockerfile") 60 | expect_match(dockerfile, "test1", all = FALSE) 61 | expect_match(dockerfile, "test2", all = FALSE) 62 | }) 63 | 64 | test_that("docker entry only appends stuff", { 65 | scoped_temporary_package() 66 | use_docker() 67 | dockerfile1 <- readLines("Dockerfile") 68 | docker_entry("test", write = TRUE, open = TRUE, append = TRUE) 69 | dockerfile2 <- readLines("Dockerfile") 70 | expect_identical(dockerfile1, dockerfile2[-length(dockerfile2)]) 71 | expect_identical(dockerfile2[length(dockerfile2)], "test") 72 | 73 | dockerfile3 <- docker_entry("test", write = FALSE, open = TRUE, append = TRUE) 74 | expect_identical(dockerfile3, c(dockerfile2, "test")) 75 | }) 76 | 77 | test_that("docker_get extracts correct lines", { 78 | scoped_temporary_project() 79 | cat(dockerfile, file = "Dockerfile") 80 | expect_identical(docker_get_packages(), 81 | c("anytime", "dplyr", "lubridate", "readr", "usethis")) 82 | }) 83 | -------------------------------------------------------------------------------- /tests/testthat/test-docker_windows_path.R: -------------------------------------------------------------------------------- 1 | context("Test windows path for Docker") 2 | test_that("path generation works", { 3 | expect_equal(docker_windows_path("C:/Users/someuser/Documents/myproject/"), 4 | "//c/Users/someuser/Documents/myproject/") 5 | }) 6 | 7 | test_that("path recognizes non windows paths", { 8 | expect_error(docker_windows_path("/Users/someuser/Documents/myproject/")) 9 | expect_error(docker_windows_path("C:/C:/Users/someuser/Documents/myproject/")) 10 | }) -------------------------------------------------------------------------------- /tests/testthat/test-gha.R: -------------------------------------------------------------------------------- 1 | test_that("github action is created only when Dockerfile exists", { 2 | op <- options() 3 | scoped_temporary_project() 4 | cat(test_rmd1, file = "test.Rmd") 5 | expect_oops(use_gha_docker()) 6 | expect_oops(use_gha_publish()) 7 | automate() 8 | expect_oops(use_gha_publish()) 9 | expect_ok(use_gha_docker()) 10 | expect_ok(use_gha_publish()) 11 | expect_proj_file(getOption("repro.gha.docker")) 12 | expect_proj_file(getOption("repro.gha.publish")) 13 | options(op) 14 | }) 15 | -------------------------------------------------------------------------------- /tests/testthat/test-hash.R: -------------------------------------------------------------------------------- 1 | git_repo_availible <- function()silent_command("git status") == 0L 2 | 3 | test_that("Git and gert give same hash", { 4 | skip_if_not(git_repo_availible()) 5 | expect_equal(current_hash(backend = "git"), current_hash(backend = "gert")) 6 | }) 7 | 8 | test_that("gert is recognized as fallback", { 9 | skip_if_not(git_repo_availible()) 10 | hash <- withr::with_options( 11 | list(repro.git = TRUE, 12 | repro.gert = TRUE), 13 | current_hash()) 14 | withr::with_options( 15 | list(repro.git = FALSE, 16 | repro.gert = TRUE), 17 | expect_equal(current_hash(), hash)) 18 | }) 19 | 20 | test_that("it actually fails if there is no git or gert", { 21 | skip_if_not(git_repo_availible()) 22 | withr::with_options(list(repro.git = FALSE, 23 | repro.gert = FALSE), { 24 | expect_error(current_hash(), "gert") 25 | expect_error(current_hash(), "Git") 26 | }) 27 | }) 28 | 29 | test_that("it fails with grace when not within a git repo", { 30 | skip_if_not(git_repo_availible()) 31 | withr::with_tempdir( 32 | withr::with_options(list(repro.git = TRUE), { 33 | expect_error(current_hash(backend = "git"), "Maybe not a Git repository.") 34 | }) 35 | ) 36 | withr::with_tempdir( 37 | withr::with_options(list(repro.gert = TRUE), { 38 | expect_error(current_hash(backend = "gert"), "could not find repository") 39 | }) 40 | ) 41 | }) 42 | -------------------------------------------------------------------------------- /tests/testthat/test-make.R: -------------------------------------------------------------------------------- 1 | context("Test Makefile related functions.") 2 | test_that("use_make creates a Makefile", { 3 | scoped_temporary_project() 4 | repro::use_make(open = TRUE) 5 | expect_proj_file("Makefile") 6 | }) 7 | 8 | test_that("use_make creates a Makefile_Docker", { 9 | scoped_temporary_project() 10 | repro::use_make(docker = TRUE, open = TRUE) 11 | expect_proj_file("Makefile") 12 | expect_proj_file("Dockerfile") 13 | expect_proj_file("Makefile_Docker") 14 | }) 15 | 16 | test_that("use_make creates a Makefile_Singularity", { 17 | scoped_temporary_project() 18 | repro::use_make(docker = TRUE, singularity = TRUE, open = TRUE) 19 | expect_proj_file("Makefile") 20 | expect_proj_file("Makefile_Singularity") 21 | }) 22 | 23 | test_that("use_make creates a custome Makefiles", { 24 | scoped_temporary_project() 25 | repro::use_make(docker = "mydocker", singularity = "mysingularity", open = TRUE) 26 | expect_proj_file("mydocker") 27 | expect_proj_file("mysingularity") 28 | }) 29 | 30 | test_that("use_make fails for Singularity without Docker", { 31 | scoped_temporary_project() 32 | expect_error(repro::use_make(docker = FALSE, singularity = TRUE, open = TRUE), 33 | "docker = TRUE", 34 | class = "usethis_error") 35 | }) 36 | 37 | test_that("use_make works for Singularity with pre-existing Docker", { 38 | scoped_temporary_project() 39 | repro::use_make(docker = TRUE) 40 | expect_proj_file("Makefile") 41 | fs::file_delete("Makefile") 42 | repro::use_make(docker = FALSE, singularity = TRUE, open = TRUE) 43 | expect_proj_file("Makefile_Singularity") 44 | }) 45 | 46 | test_that("use_make creates a Makefile_Docker if there is a Dockerfile", { 47 | scoped_temporary_project() 48 | use_docker() 49 | repro::use_make() 50 | expect_proj_file("Makefile_Docker") 51 | }) 52 | 53 | test_that("use_make_docker creates all files it should", { 54 | 55 | scoped_temporary_project() 56 | use_make_docker() 57 | expect_proj_file("Makefile_Docker") 58 | expect_proj_file("Dockerfile") 59 | expect_proj_file(".dockerignore") 60 | 61 | scoped_temporary_project() 62 | withr::with_options( 63 | list(repro.makefile.docker = "mydocker"), 64 | { 65 | use_make_docker() 66 | expect_proj_file("mydocker") 67 | expect_proj_file("Dockerfile") 68 | expect_proj_file(".dockerignore") 69 | }) 70 | }) 71 | 72 | test_that("use_make_singularity creates all files it should", { 73 | scoped_temporary_project() 74 | use_make_singularity() 75 | expect_proj_file("Makefile_Singularity") 76 | 77 | scoped_temporary_project() 78 | withr::with_options( 79 | list(repro.makefile.singularity = "mysingularity"), 80 | { 81 | use_make_singularity() 82 | expect_proj_file("mysingularity") 83 | }) 84 | }) 85 | 86 | test_that("Existing Makefile remains untouched.", { 87 | scoped_temporary_project() 88 | cat("all: test.txt", file = "Makefile") 89 | expect_ok(repro::use_make()) 90 | expect_message(repro::use_make(), "already use Make") 91 | }) 92 | -------------------------------------------------------------------------------- /tests/testthat/test-reproduce.R: -------------------------------------------------------------------------------- 1 | test_that("reproduce recognizes a standard repro project", { 2 | opts <- options() 3 | scoped_temporary_project() 4 | repro_template(".") 5 | automate() 6 | expect_message(reproduce(cache = TRUE), regexp = "make docker") 7 | expect_message(reproduce(cache = FALSE), regexp = "-B") 8 | expect_equal(reproduce(cache = FALSE), "make docker &&\nmake -B DOCKER=TRUE ") 9 | options(opts) 10 | }) 11 | 12 | test_that("reproduce recognizes a standard repro project", { 13 | opts <- options() 14 | scoped_temporary_project() 15 | repro_template(".") 16 | automate() 17 | file_delete(".repro/Makefile_Docker") 18 | expect_message(reproduce(cache = TRUE), regexp = "make") 19 | expect_message(reproduce(cache = FALSE), regexp = "-B") 20 | options(opts) 21 | }) -------------------------------------------------------------------------------- /tests/testthat/test-rerun.R: -------------------------------------------------------------------------------- 1 | test_that("rerun is identical with reproduce", { 2 | opts <- options() 3 | scoped_temporary_project() 4 | repro_template(".") 5 | automate() 6 | expect_equal(suppressWarnings(rerun(cache = TRUE)), reproduce(cache = TRUE)) 7 | expect_equal(suppressWarnings(rerun(cache = FALSE)), reproduce(cache = FALSE)) 8 | options(opts) 9 | }) 10 | 11 | test_that("rerun warns about deprication", { 12 | opts <- options() 13 | scoped_temporary_project() 14 | repro_template(".") 15 | automate() 16 | expect_warning(rerun(cache = TRUE), "deprecated") 17 | expect_warning(rerun(cache = TRUE), "renamed") 18 | options(opts) 19 | }) -------------------------------------------------------------------------------- /tests/testthat/test-uses.R: -------------------------------------------------------------------------------- 1 | test_that("uses works", { 2 | op <- options() 3 | scoped_temporary_project() 4 | cat(test_rmd1, file = "test.Rmd") 5 | expect_oops(uses_docker()) 6 | expect_oops(uses_make()) 7 | automate() 8 | expect_ok(uses_docker()) 9 | expect_ok(uses_make()) 10 | }) 11 | -------------------------------------------------------------------------------- /tests/testthat/test-yaml.R: -------------------------------------------------------------------------------- 1 | context("Test yaml related functions") 2 | 3 | test_that("yaml is corectly read", { 4 | scoped_temporary_project() 5 | cat(test_rmd1, file = "test.Rmd") 6 | expect_identical(names(read_yaml("test.Rmd")), 7 | c("title", "author", "date", "output", "repro")) 8 | expect_identical(names(yaml_repro(read_yaml("test.Rmd"))), 9 | c("packages", "data", "scripts", "output")) 10 | }) 11 | 12 | test_that("packages are recognized", { 13 | scoped_temporary_project() 14 | cat(test_rmd1, file = "test.Rmd") 15 | fs::dir_create("test") 16 | cat(test_rmd2, file = "test/test2.Rmd") 17 | packages <- yamls_packages() 18 | expect_true(all(c("dplyr", "usethis", "anytime", "lubridate", "readr") %in% 19 | packages)) 20 | }) 21 | 22 | test_that("RMDs without yaml are skipped", { 23 | scoped_temporary_project() 24 | cat(test_rmd1, file = "test.Rmd") 25 | fs::dir_create("test") 26 | cat(test_rmd2, file = "test/test2.Rmd") 27 | cat("# Title\nTextText\n", file = "test/test3.Rmd") 28 | 29 | packages <- yamls_packages() 30 | expect_true(all(c("dplyr", "usethis", "anytime", "lubridate", "readr") %in% 31 | packages)) 32 | }) 33 | 34 | test_that("yaml boundaries with whitespace work", { 35 | scoped_temporary_project() 36 | test_rmd1_space <- strsplit(test_rmd1, "\n", fixed = TRUE)[[1]] 37 | test_rmd1_space[2] <- "--- " 38 | cat(test_rmd1_space, file = "test.Rmd", sep = "\n") 39 | expected <- 40 | list( 41 | title = "Test", 42 | author = "Aaron Peikert", 43 | date = "1/13/2020", 44 | output = "html_document", 45 | repro = list( 46 | packages = c("dplyr", 47 | "usethis", "anytime"), 48 | data = "iris.csv", 49 | scripts = c("load.R", 50 | "clean.R") 51 | ) 52 | ) 53 | expect_identical(read_yaml("test.Rmd"), expected) 54 | }) 55 | 56 | test_that("yaml needs to be at the top", { 57 | scoped_temporary_project() 58 | test_rmd1_top <- strsplit(test_rmd1, "\n", fixed = TRUE)[[1]] 59 | test_rmd1_top <- c(LETTERS, test_rmd1_top) 60 | cat(test_rmd1_top, file = "test.Rmd", sep = "\n") 61 | expect_null(read_yaml("test.Rmd")) 62 | }) 63 | -------------------------------------------------------------------------------- /tests/testthat/test-zzz.R: -------------------------------------------------------------------------------- 1 | test_that("onload sets options to na", { 2 | expect_invisible(.onLoad()) 3 | expect_true(is.na(getOption("repro.docker"))) 4 | expect_true(is.na(getOption("repro.make"))) 5 | expect_true(is.na(getOption("repro.git"))) 6 | expect_true(is.na(getOption("repro.choco"))) 7 | expect_true(is.na(getOption("repro.brew"))) 8 | expect_true(is.na(getOption("repro.os"))) 9 | expect_true(is.na(getOption("repro.renv"))) 10 | expect_true(is.na(getOption("repro.worcs"))) 11 | expect_true(is.na(getOption("repro.targets"))) 12 | }) 13 | 14 | test_that("onAttach sends a message", { 15 | expect_message(.onAttach()) 16 | }) 17 | 18 | test_that("onAttach is returns invisibly", { 19 | expect_invisible(.onAttach()) 20 | }) 21 | 22 | test_that("silent_command is silent", { 23 | expect_output(silent_command("ls"), NA) 24 | }) 25 | 26 | test_that("get_os() fails while testing.",{ 27 | expect_error(get_os(), regexp = "testing") 28 | }) --------------------------------------------------------------------------------