-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsetupProject.R
More file actions
3096 lines (2768 loc) · 128 KB
/
setupProject.R
File metadata and controls
3096 lines (2768 loc) · 128 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
utils::globalVariables(c(
".", "i.module", "i.objectClass", "objectClass", "objectName",
"i.newValue", "i.oldValue", "newValue", "oldValue", "modulesNoVersion"
))
#' Sets up a new or existing SpaDES project
#'
#' @description `setupProject` calls a sequence of functions in this order:
#' `setupOptions` (first time), `setupPaths`, `setupRestart`,
#' `setupFunctions`, `setupModules`, `setupPackages`, `setupSideEffects`,
#' `setupOptions` (second time), `setupParams`, and `setupGitIgnore`.
#'
#' This sequence will create folder structures, install missing packages from those
#' listed in either the `packages`, `require` arguments or in the modules `reqdPkgs` fields,
#' load packages (only those in the `require` argument), set options, download or
#' confirm the existence of modules. It will also return elements that can be passed
#' directly to `simInit` or `simInitAndSpades`, specifically, `modules`, `params`,
#' `paths`, `times`, and any named elements passed to `...`. This function will also
#' , if desired, change the .Rprofile file for this project so that every time
#' the project is opened, it has a specific `.libPaths()`.
#'
#' There are a number of convenience elements described in the section below. See Details.
#' Because of this sequence, users can take advantage of settings (i.e., objects)
#' that happen (are created) before others. For example, users can set `paths`
#' then use the `paths` list to set `options` that will can update/change `paths`,
#' or set `times` and use the `times` list for certain entries in `params`.
#'
#'
#' @param name Optional. If supplied, the name of the project. If not supplied, an
#' attempt will be made to extract the name from the `paths[["projectPath"]]`.
#' If this is a GitHub project, then it should indicate the full Github
#' repository and branch name, e.g., `"PredictiveEcology/WBI_forecasts@ChubatyPubNum12"`
#' @param paths a list with named elements, specifically, `modulePath`, `projectPath`,
#' `packagePath` and all others that are in `SpaDES.core::setPaths()`
#' (i.e., `inputPath`, `outputPath`, `scratchPath`, `cachePath`, `rasterTmpDir`).
#' Each of these has a sensible default, which will be overridden but any user
#' supplied values.
#' See [setup].
#' @param modules a character string of modules to pass to `getModule`. These
#' should be one of: simple name (e.g., `fireSense`) which will be searched for locally
#' in the `paths[["modulePath"]]`; or a GitHub repo with branch (`GitHubAccount/Repo@branch` e.g.,
#' `"PredictiveEcology/Biomass_core@development"`); or a character vector that identifies
#' one or more module folders (local or GitHub) (not the module .R script).
#' If the entire project is a git repository,
#' then it will not try to re-get these modules; instead it will rely on the user
#' managing their git status outside of this function.
#' See [setup].
#' @param times Optional. This will be returned if supplied; if supplied, the values
#' can be used in e.g., `params`, e.g., `params = list(mod = list(startTime = times$start))`.
#' See help for `SpaDES.core::simInit`.
#' @param config Still experimental linkage to the `SpaDES.config` package. Currently
#' not working.
#' @param packages Optional. A vector of packages that must exist in the `libPaths`.
#' This will be passed to `Require::Install`, i.e., these will be installed, but
#' not attached to the search path. See also the `require` argument. To force skip
#' of package installation (without assessing modules), set `packages = NULL`
#' @param require Optional. A character vector of packages to install *and* attach
#' (with `Require::Require`). These will be installed and attached at the start
#' of `setupProject` so that a user can use these during `setupProject`.
#' See [setup]
#' @param options Optional. Either a named list to be passed to `options`
#' or a character vector indicating one or more file(s) to source,
#' in the order provided. These will be parsed locally (not
#' the `.GlobalEnv`), so they will not create globally accessible objects. NOTE:
#' `options` is run 2x within `setupProject`, once before `setupPaths` and once
#' after `setupPackages`. This occurs because many packages use options for their
#' behaviour (need them set before e.g., `Require::require` is run; but many packages
#' also change `options` at startup. See details.
#' See [setup].
#' @param params Optional. Similar to `options`, however, this named list will be
#' returned, i.e., there are no side effects.
#' See [setup].
#' @param sideEffects Optional. This can be an expression or one or more file names or
#' a code chunk surrounded by `{...}`.
#' If a non-text file name is specified (e.g., *not .txt or .R* currently),
#' these files will simply be downloaded, using their relative path as specified
#' in the github notation. They will be downloaded or accessed locally at that
#' relative path.
#' If these file names represent scripts (*.txt or .R), this/these will be parsed and evaluated,
#' but nothing is returned (i.e., any assigned objects are not returned). This is intended
#' to be used for operations like cloud authentication or configuration functions
#' that are run for their side effects only.
#' @param functions A set of function definitions to be used within `setupProject`.
#' These will be returned as a list element. If function definitions require non-base
#' packages, prefix the function call with the package e.g., `terra::rast`. When
#' using `setupProject`, the `functions` argument is evaluated after `paths`, so
#' it cannot be used to define functions that help specify `paths`.
#' @param useGit (if not FALSE, then experimental still). There are two levels at which a project
#' can use GitHub, either the `projectPath` and/or the `modules`. Any given
#' project can have one or the other, or both of these under git control. If "both",
#' then this function will assume that git submodules will be used for the `modules`.
#' A logical or `"sub"` for *submodule*. If `"sub"`, then this function
#' will attempt to clone the identified `modules` *as git submodules*. This will only
#' work if the `projectPath` is a git repository. If the project is already a git
#' repository because the user has set that up externally to this function call, then
#' this function will add the `modules` as git submodules. If it is not already,
#' it will use `git clone` for each module. After git clone or submodule add are run,
#' it will run `git checkout` for the named branch and then `git pull`
#' to get and change branch for each module, according to its specification in
#' `modules`. If `FALSE`, this function will download modules with `getModules`.
#' NOTE: *CREATING* A
#' GIT REPOSITORY AT THE PROJECT LEVEL AND SETTING MODULES AS GIT SUBMODULES IS
#' EXPERIMENTAL. IT IS FINE IF THE PROJECT HAS BEEN MANUALLY SET UP TO BE
#' A GIT REPOSITORY WITH SUBMODULES: THIS FUNCTION WILL ONLY EVALUTE PATHS. This can
#' be set with the `option(SpaDES.project.useGit = xxx)`.
#' @param standAlone A logical. Passed to `Require::standAlone`. This keeps all
#' packages installed in a project-level library, if `TRUE`. Default is `TRUE`.
#' @param libPaths Deprecated. Use `paths = list(packagePath = ...)`.
#' @param Restart Logical or character. If either `TRUE` or a character,
#' and if the `projectPath` is not the current path, and the session is in
#' RStudio and interactive, it will try to restart Rstudio in the projectPath with
#' a new Rstudio project. If character, it should represent the filename
#' of the script that contains the `setupProject` call that should be copied to
#' the new folder and opened. If `TRUE`, it will use the active file as the one
#' that should be copied to the new projectPath and opened in the Rstudio project.
#' If successful, this will create an RStudio Project file (and .Rproj.user
#' folder), restart with a new Rstudio session with that new project and with a root
#' path (i.e. working directory) set to `projectPath`. Default is `FALSE`, and no
#' RStudio Project is created.
#' @param updateRprofile Logical. Should the `paths$packagePath` be set in the `.Rprofile`
#' file for this project. Note: if `paths$packagePath` is within the `tempdir()`,
#' then there will be a warning, indicating this won't persist. If the user is
#' using `Rstudio` and the `paths$projectPath` is not the root of the current
#' Rstudio project, then a warning will be given, indicating the .Rprofile may not
#' be read upon restart.
#' @param setLinuxBinaryRepo Logical. Should the binary RStudio Package Manager be used
#' on Linux (ignored if Windows)
#' @param studyArea Optional. If a list, it will be passed to
#' `geodata::gadm`. To specify a country other than the default `"CAN"`,
#' the list must have a named element, `"country"`. All other named elements
#' will be passed to `gadm`. 2 additional named elements can be passed for
#' convenience, `subregion = "..."`, which will be grepped with the column
#' `NAME_1`, and `epsg = "..."`, so a user can pass an `epsg.io` code to
#' reproject the `studyArea`. See examples.
#' @param overwrite Logical vector or character vector, however, only `getModule` will respond
#' to a vector of values. If length-one `TRUE`, then all files that were previously downloaded
#' will be overwritten throughout the sequence of `setupProject`. If a vector of
#' logical or character, these will be passed to `getModule`: only the named
#' modules will be overwritten or the logical vector of the modules.
#' NOTE: if a vector, no other file specified anywhere in `setupProject` will be
#' overwritten except a module that/those names, because
#' only `setupModules` is currently responsive to a vector. To have fine grained control,
#' a user can just manually delete a file, then rerun.
#' @param dots Any other named objects passed as a list a user might want for other elements.
#' @param defaultDots A named list of any arbitrary R objects.
#' These can be supplied to give default values to objects that
#' are otherwise passed in with the `...`, i.e., not specifically named for these
#' `setup*` functions. If named objects are supplied as top-level arguments, then
#' the `defaultDots` will be overridden. This can be particularly useful if the
#' arguments passed to `...` do not always exist, but rely on external e.g., batch
#' processing to optionally fill them. See examples.
#' @param envir The environment where `setupProject` is called from. Defaults to
#' `parent.frame()` which should be fine in most cases and user shouldn't need
#' to set this
#' @param ... further named arguments that acts like `objects`, but a different
#' way to specify them. These can be anything. The general use case
#' is to create the `objects` that are would be passed to
#' `SpaDES.core::simInit`, or `SpaDES.core::simInitAndSpades`,
#' (e.g. `studyAreaName` or `objects`) or additional objects to be passed to the simulation
#' (in older versions of `SpaDES.core`, these were passed as a named list
#' to the `objects` argument). **Order matters**. These are sequentially evaluated,
#' and also any arguments that are specified before the named arguments
#' e.g., `name`, `paths`, will be evaluated prior to any of the named arguments,
#' i.e., "at the start" of the `setupProject`.
#' If placed after the first named argument, then they will be evaluated at the
#' end of the `setupProject`, so can access all the packages, objects, etc.
#'
#' @include imports.R
#' @export
#'
#' @section Faster runtime after project is set up:
#'
#' There are a number of checks that occur during `setupProject`. These take time, particularly
#' after an R restart (there is some caching in RAM that occurs, but this will only speed
#' things up if there is no restart of R). To get the "fastest", these options or settings
#' will speed things up, at the expense of not being completely re-runnable.
#' You can add one or more of these to the arguments. These will only be useful after a project
#' is set up, i.e., `setupProject` and `SpaDES.core::simInit` has/have been run at least once
#' to completion (so packages are installed).
#'
#' ```
#' options = c(
#' reproducible.useMemoise = TRUE, # For caching, use memory objects
#' Require.cloneFrom = Sys.getenv("R_LIBS_USER"),# Use personal library as possible source of packages
#' spades.useRequire = FALSE, # Won't install packages/update versions
#' spades.moduleCodeChecks = FALSE, # moduleCodeChecks checks for metadata mismatches
#' reproducible.inputPaths = "~/allData"), # For sharing data files across projects
#' packages = NULL, # Prevents any packages installs with setupProject
#' useGit = FALSE # Prevents checks using git
#' ```
#' These will be set early in `setupProject`, so will affect the running of `setupProject`.
#' If the user manually sets one of these in addition to setting these, the user options will
#' override these.
#' The remining causes of `setupProject` being "slow" will be loading the required packages.
#'
#' These options/arguments can now be set all at once
#' (with caution as these changes will affect how your
#' script will be run) with `options(SpaDES.project.fast = TRUE)` or in the `options` argument.
#'
#'
#' @section Objective:
#'
#' The overarching objectives for these functions are:
#'
#' \enumerate{
#' \item To prepare what is needed for `simInit`.
#' \item To help a user eliminate virtually all assignments to the `.GlobalEnv`,
#' as these create and encourage spaghetti code that becomes unreproducible
#' as the project increases in complexity.
#' \item Be very simple for beginners, but powerful enough to expand to almost
#' any needs of arbitrarily complex projects, using the same structure
#' \item Deal with the complexities of R package installation and loading when
#' working with modules that may have been created by many users
#' \item Create a common SpaDES project structure, allowing
#' easy transition from one project to another, regardless of complexity.
#' }
#'
#'
#' @section Convenience elements:
#'
#' \subsection{Sequential evaluation}{
#' Throughout these functions, efforts have been made to implement sequential evaluation,
#' within files and within lists. This means that a user can *use* the values from an
#' upstream element in the list. For example, the following where `projectPath` is
#' part of the list that will be assigned to the `paths` argument and it is then
#' used in the subsequent list element is valid:
#'
#' ```
#' setupPaths(paths = list(projectPath = "here",
#' modulePath = file.path(paths[["projectPath"]], "modules")))
#' ```
#' Because of such sequential evaluation, `paths`, `options`, and `params` files
#' can be sequential lists that have impose a hierarchy specified
#' by the order. For example, a user can first create a list of *default* options,
#' then several lists of user-desired options behind an `if (user("emcintir"))`
#' block that add new or override existing elements, followed by `machine` specific
#' values, such as paths.
#' }
#'
#' ```
#' setupOptions(
#' maxMemory <- 5e+9 # if (grepl("LandWeb", runName)) 5e+12 else 5e+9
#'
#' # Example -- Use any arbitrary object that can be passed in the `...` of `setupOptions`
#' # or `setupProject`
#' if (.mode == "development") {
#' list(test = 2)
#' }
#' if (machine("A127")) {
#' list(test = 3)
#' }
#' )
#' ````
#'
#' \subsection{Values and/or files}{
#' The arguments, `paths`, `options`, and `params`, can all
#' understand lists of named values, character vectors, or a mixture by using a list where
#' named elements are values and unnamed elements are character strings/vectors. Any unnamed
#' character string/vector will be treated as a file path. If that file path has an `@` symbol,
#' it will be assumed to be a file that exists on a GitHub repository in `https://github.com`.
#' So a user can pass values, or pointers to remote and/or local paths that themselves have values.
#'
#' The following will set an option as declared, plus read the local file (with relative
#' path), plus download and read the cloud-hosted file.
#'
#' ```
#' setupProject(
#' options = list(reproducible.useTerra = TRUE,
#' "inst/options.R",
#' "PredictiveEcology/SpaDES.project@transition/inst/options.R")
#' )
#' )
#' ```
#' This approach allows for an organic growth of complexity, e.g., a user begins with
#' only named lists of values, but then as the number of values increases, it may be
#' helpful to put some in an external file.
#'
#' NOTE: if the GitHub repository is *private* the user *must* configure their GitHub
#' token by setting the GITHUB_PAT environment variable -- unfortunately, the `usethis`
#' approach to setting the token will not work at this moment.
#' }
#'
#' \subsection{Specifying `paths`, `options`, `params`}{
#' If `paths`, `options`, and/or `params` are a character string
#' or character vector (or part of an unnamed list element) the string(s)
#' will be interpreted as files to parse. These files should contain R code that
#' specifies *named lists*, where the names are one or more `paths`, `options`,
#' or are module names, each with a named list of parameters for that named module.
#' This last named list for `params` follows the convention used for the `params` argument in
#' `simInit(..., params = )`.
#'
#' These files can use `paths`, `times`, plus any previous list in the sequence of
#' `params` or `options` specified. Any functions that are used must be available,
#' e.g., prefixed `Require::normPath` if the package has not been loaded (as recommended).
#'
#' If passing a file to `options`, it should **not set** `options()` explicitly;
#' only create named lists. This enables options checking/validating
#' to occur within `setupOptions` and `setupParams`. A simplest case would be a file with this:
#' `opts <- list(reproducible.destinationPath = "~/destPath")`.
#'
#' All named lists will be parsed into their own environment, and then will be
#' sequentially evaluated (i.e., subsequent lists will have access to previous lists),
#' with each named elements setting or replacing the previously named element of the same name,
#' creating a single list. This final list will be assigned to, e.g., `options()` inside `setupOptions`.
#'
#' Because each list is parsed separately, they to not need to be assigned objects;
#' if they are, the object name can be any name, even if similar to another object's name
#' used to built the same argument's (i.e. `paths`, `params`, `options`) final list.
#' Hence, in an file to passed to `options`, instead of incrementing the list as:
#'
#' ```
#' a <- list(optA = 1)
#' b <- append(a, list(optB = 2))
#' c <- append(b, list(optC = 2.5))
#' d <- append(c, list(optD = 3))
#' ```
#'
#' one can do:
#' ```
#' a <- list(optA = 1)
#' a <- list(optB = 2)
#' c <- list(optC = 2.5)
#' list(optD = 3)
#' ```
#'
#' NOTE: only atomics (i.e., character, numeric, etc.), named lists, or either of these
#' that are protected by 1 level of "if" are parsed. This will not work, therefore,
#' for other side-effect elements, like authenticating with a cloud service.
#'
#' Several helper functions exist within `SpaDES.project` that may be useful, such
#' as `user(...)`, `machine(...)`
#' }
#'
#' \subsection{Can hard code arguments that may be missing}{
#' To allow for batch submission, a user can specify code `argument = value` even if `value`
#' is missing. This type of specification will not work in normal parsing of arguments,
#' but it is designed to work here. In the next example, `.mode = .mode` can be specified,
#' but if R cannot find `.mode` for the right hand side, it will just skip with no error.
#' Thus a user can source a script with the following line from batch script where `.mode`
#' is specified. When running this line without that batch script specification, then this
#' will assign no value to `.mode`. We include `.nodes` which shows an example of
#' passing a value that does exist. The non-existent `.mode` will be returned in the `out`,
#' but as an unevaluated, captured list element.
#'
#' ```
#' .nodes <- 2
#' out <- setupProject(.mode = .mode,
#' .nodes = .nodes,
#' options = "inst/options.R"
#' )
#' ```
#' }
#'
#' @return
#' `setupProject` will return a named list with elements `modules`, `paths`, `params`, and `times`.
#' The goal of this list is to contain list elements that can be passed directly
#' to `simInit`.
#'
#' It will also append all elements passed by the user in the `...`.
#' This list can be passed directly to `SpaDES.core::simInit()` or
#' `SpaDES.core::simInitAndSpades()` using a `do.call()`. See example.
#'
#' NOTE: both `projectPath` and `packagePath` will be omitted in the `paths` list
#' as they are used to set current directory (found with `getwd()`) and `.libPaths()[1]`,
#' but are not accepted by `simInit`. `setupPaths` will still return these two paths as its
#' outputs are not expected to be passed directly to `simInit` (unlike `setupProject` outputs).
#'
#' @importFrom Require extractPkgName
#' @importFrom stats na.omit
#' @inheritParams Require::Require
#' @inheritParams Require::setLibPaths
#' @rdname setupProject
#' @seealso [setupPaths()], [setupOptions()], [setupPackages()],
#' [setupModules()], [setupGitIgnore()]. Also, helpful functions such as
#' [user()], [machine()], [node()]
#' @seealso `vignette("i-getting-started", package = "SpaDES.project")`
#'
#' @examples
#' ## For more examples:
#' vignette("i-getting-started", package = "SpaDES.project")
#'
#' library(SpaDES.project)
#'
#' \dontshow{origDir <- getwd()
#' tmpdir <- Require::tempdir2() # for testing tempdir2 is better}
#' \dontshow{
#' if (is.null(getOption("repos"))) {
#' options(repos = c(CRAN = "https://cloud.r-project.org"))
#' }
#' setwd(tmpdir)
#' }
#' ## simplest case; just creates folders
#' out <- setupProject(
#' paths = list(projectPath = ".") #
#' )
#' \dontshow{setwd(origDir)}
setupProject <- function(name, paths, modules, packages,
times, options, params, sideEffects, functions, config,
require = NULL, studyArea = NULL,
Restart = getOption("SpaDES.project.Restart", FALSE),
useGit = getOption("SpaDES.project.useGit", FALSE),
setLinuxBinaryRepo = getOption("SpaDES.project.setLinuxBinaryRepo", TRUE),
standAlone = getOption("SpaDES.project.standAlone", TRUE), libPaths = NULL,
updateRprofile = getOption("SpaDES.project.updateRprofile", TRUE),
overwrite = getOption("SpaDES.project.overwrite", FALSE), # envir = environment(),
verbose = getOption("Require.verbose", 1L),
defaultDots, envir = parent.frame(),
dots, ...) {
makeUpdateRprofileSticky(updateRprofile)
origGetWd <- getwd()
if (isTRUE(Restart))
on.exit(setwd(origGetWd), add = TRUE)
envirCur = environment()
origArgOrder <- names(tail(sys.calls(), 1)[[1]])
if (is.null(origArgOrder)) {
firstNamedArg <- 0
} else {
argsAreInFormals <- origArgOrder %in% formalArgs(setupProject)
firstNamedArg <- if (isTRUE(any(argsAreInFormals))) min(which(argsAreInFormals)) else Inf
}
dotsSUB <- as.list(substitute(list(...)))[-1]
dotsLater <- dotsSUB
if (firstNamedArg > 2) { # there is always an empty one at first slot
firstSet <- if (is.infinite(firstNamedArg)) seq(length(origArgOrder) - 1) else (1:(firstNamedArg - 2))
dotsLater <- dotsSUB[-firstSet]
dotsSUB <- dotsSUB[firstSet]
dotsSUB <- dotsToHereOuter(dots, dotsSUB, defaultDots)
}
functionsSUB <- substitute(functions)
timesSUB <- substitute(times) # must do this in case the user passes e.g., `list(fireStart = times$start)`
if (!missing(timesSUB))
times <- evalSUB(val = timesSUB, envir = envirCur, valObjName = "times", envir2 = envir)
modulesSUB <- substitute(modules) # must do this in case the user passes e.g., `list(fireStart = times$start)`
paramsSUB <- substitute(params) # must do this in case the user passes e.g., `list(fireStart = times$start)`
optionsSUB <- substitute(options) # must do this in case the user passes e.g., `list(fireStart = times$start)`
pathsSUB <- substitute(paths) # must do this in case the user passes e.g., `list(modulePath = paths$projectpath)`
sideEffectsSUB <- substitute(sideEffects)
libPaths <- substitute(libPaths)
if (missing(times))
times <- list(start = 0, end = 1)
pathsSUB <- checkProjectPath(pathsSUB, name, envir = envirCur, envir2 = envir)
if (missing(name)) {
name <- basename(normPath(pathsSUB[["projectPath"]]))
} else {
name <- checkNameProjectPathConflict(name, pathsSUB)
}
inProject <- isInProject(name)
# setupOptions is run twice -- because package startup often changes options
optsFirst <- setupOptions(name, optionsSUB, pathsSUB, times, overwrite = isTRUE(overwrite),
envir = envirCur, useGit = useGit,
updateRprofile = updateRprofile,
verbose = verbose - 1)
if (isTRUE(getOption("SpaDES.project.fast"))) {
base::options(fastOptions())
packages <- NULL
useGit <- FALSE
}
paths <- setupPaths(name, pathsSUB, inProject, standAlone, libPaths,
Restart = Restart, defaultDots = defaultDots,
useGit = useGit,
updateRprofile = updateRprofile, verbose = verbose) # don't pass envir because paths aren't evaluated yet
inProject <- isInProject(name)
setupRestart(updateRprofile = updateRprofile, paths, name, inProject, useGit = useGit,
Restart = Restart, origGetWd, verbose) # This may restart
# Need to assess if this is a new project locally, but the remote exists
usingGit <- checkUseGit(useGit)
gitUserName <- NULL
if (isTRUE(usingGit)) {
isLocalGitRepoAlready <- isProjectGitRepo(pathsSUB$projectPath, inProject)
if (isFALSE(isLocalGitRepoAlready)) {
gitUserName <- checkGitRemote(name, pathsSUB)
}
}
# this next puts them in this environment, returns NULL
functions <- setupFunctions(functionsSUB, paths = paths, envir = envirCur)
modulePackages <- setupModules(name, paths, modulesSUB, inProject = inProject, useGit = useGit,
gitUserName = gitUserName, updateRprofile = updateRprofile,
overwrite = overwrite, envir = envirCur, verbose = verbose)
modules <- Require::extractPkgName(names(modulePackages))
names(modules) <- names(modulePackages)
if (missing(packages))
packages <- character()
setupPackages(packages, modulePackages, require = require, paths = paths,
setLinuxBinaryRepo = setLinuxBinaryRepo,
standAlone = standAlone,
libPaths = paths[["packagePath"]], envir = envirCur, verbose = verbose)
# This next is to set the terra tempdir; don't do it in the cases where terra is not used
# The longer unique(...) commented next is much slower; they are identical results
# allPkgs <- unique(Require::extractPkgName(c(packages, unname(unlist(modulePackages)))))
allPkgs <- c(packages, unname(unlist(modulePackages)))
if (any(grepl("\\<terra\\>", allPkgs))) {
terra::terraOptions(tempdir = paths$terraPath)
}
sideEffectsSUB <- setupSideEffects(name, sideEffectsSUB, paths, times, overwrite = isTRUE(overwrite),
envir = envirCur, verbose = verbose)
# 2nd time
opts <- setupOptions(name, optionsSUB, paths, times, overwrite = isTRUE(overwrite), envir = envirCur,
useGit = useGit, updateRprofile = updateRprofile, verbose = verbose - 1)
if (!is.null(opts$newOptions))
opts <- mergeOpts(opts, optsFirst, verbose)
if (isTRUE(getOption("SpaDES.project.fast"))) {
message("Using fast options:")
df <- fastOptions()[!names(fastOptions()) %in% names(opts[["newOptions"]])]
df <- df[!sapply(df, is.null)]
reproducible::messageDF(data.frame(option = names(df), val = unlist(df)))
}
options <- opts[["newOptions"]] # put into this environment so parsing can access
# Run 2nd time after sideEffects & setupOptions -- may not be necessary
# setupPackages(packages, modulePackages, require = require,
# setLinuxBinaryRepo = setLinuxBinaryRepo,
# standAlone = standAlone,
# libPaths = paths[["packagePath"]], envir = envirCur, verbose = verbose)
if (!missing(config)) {
# messageVerbose("config is supplied; using `SpaDES.config` package internals", verbose = verbose)
# if (!requireNamespace("SpaDES.config", quietly = TRUE)) {
# Require::Install("PredictiveEcology/SpaDES.config@development")
# }
messageWarnStop("config is not yet setup to run with SpaDES.project")
# if (FALSE)
# out <- do.call(SpaDES.config::useConfig, append(
# list(projectName = config,
# projectPath = paths[["projectPath"]], paths = paths),
# localVars))
}
# TODO from here to out <- should be brought into the "else" block when `SpaDES.config is worked on`
params <- setupParams(name, paramsSUB, paths, modules, times, options = opts[["newOptions"]],
overwrite = isTRUE(overwrite), envir = envirCur, verbose = verbose)
studyAreaSUB <- substitute(studyArea)
if (!is.null(studyAreaSUB)) {
dotsSUB$studyArea <- setupStudyArea(studyAreaSUB, paths, envir = parent.frame(), verbose = verbose)
studyArea <- dotsSUB$studyArea
}
if (length(dotsLater)) {
dotsLater <- dotsToHereOuter(dots, dotsLater, defaultDots)
dotsSUB <- Require::modifyList2(dotsSUB, dotsLater)
}
setupGitIgnore(paths, gitignore = getOption("SpaDES.project.gitignore", TRUE), verbose)
# Put Dots in order
if (length(dotsSUB) > 1)
dotsSUB <- dotsSUB[na.omit(match(origArgOrder, names(dotsSUB)))]
pathsOrig <- paths
extras <- setdiff(names(paths), spPaths)
paths <- paths[spPaths]
attr(paths, "extraPaths") <- pathsOrig[extras]
out <- append(list(
modules = modules,
paths = paths, # this means we lose the packagePath --> but it is in .libPaths()[1]
# we also lose projectPath --> but this is getwd()
params = params,
times = times), dotsSUB)
if (!is.null(options)) {
attr(out, "projectOptions") <- opts$updates
}
return(out)
}
#' Individual `setup*` functions that are contained within `setupProject`
#'
#' These functions will allow more user control, though in most circumstances,
#' it should be unnecessary to call them directly.
#'
#' @details
#' `setPaths` will fill in any paths that are not explicitly supplied by the
#' user as a named list. These paths that can be set are:
#' `projectPath`, `packagePath`, `cachePath`, `inputPath`,
#' `modulePath`, `outputPath`, `rasterPath`, `scratchPath`, `terraPath`.
#' These are grouped thematically into three groups of paths:
#' `projectPath` and `packagePath` affect the project, regardless
#' of whether a user uses SpaDES modules. `cachePath`, `inputPath`, `outputPath` and
#' `modulePath` are all used by SpaDES within module contexts. `scratchPath`,
#' `rasterPath` and `terraPath` are all "temporary" or "scratch" directories.
#'
#' @return
#' `setupPaths` returns a list of paths that are created. `projectPath` will be
#' assumed to be the base of other non-temporary and non-R-library paths. This means
#' that all paths that are directly used by `simInit` are assumed to be relative
#' to the `projectPath`. If a user chooses to specify absolute paths, then they will
#' be returned as is. It is also called for its
#' side effect which is to call `setPaths`, with each of these paths as an argument.
#' See table for details. If a user supplies extra paths not useable by `SpaDES.core::simInit`,
#' these will added as an attribute ("extraPaths") to the `paths` element
#' in the returned object. These will still exist directly in the returned list
#' if a user uses `setupPaths` directly, but these will not be returned with
#' `setupProject` because `setupProject` is intended to be used with `SpaDES.core::simInit`.
#' In addition, three paths will be added to this same attribute automatically:
#' `projectPath`, `packagePath`, and `.prevLibPaths` which is the previous value for
#' `.libPaths()` before changing to `packagePath`.
#'
#' @section Paths:
#' \tabular{lll}{
#' **Path** \tab **Default if not supplied by user** \tab Effects \cr
#' \tab *Project Level Paths* \tab \cr
#' `projectPath`\tab if `getwd()` is `name`, then just `getwd`; if not
#' `file.path(getwd(), name)` \tab If current project is not this project
#' and using `Rstudio`, then the current
#' project will close and a new project will
#' open in the same Rstudio session, unless
#' `Restart = FALSE`\cr
#' `packagePath`\tab `file.path(tools::R_user_dir("data"), name, "packages",
#' version$platform, substr(getRversion(), 1, 3))`
#' \tab appends this path to `.libPaths(packagePath)`,
#' unless `standAlone = TRUE`, in which case,
#' it will set `.libPaths(packagePath,
#' include.site = FALSE)` to this path \cr
#' ------ \tab ----------- \tab ----- \cr
#' \tab *Module Level Paths* \tab \cr
#' `cachePath` \tab `file.path(projectPath, "cache")` \tab `options(reproducible.cachePath = cachePath)`\cr
#' `inputPath` \tab `file.path(projectPath, "inputs")` \tab `options(spades.inputPath = inputPath)`\cr
#' `modulePath` \tab `file.path(projectPath, "modules")` \tab `options(spades.inputPath = outputPath)` \cr
#' `outputPath` \tab `file.path(projectPath, "outputs")` \tab `options(spades.inputPath = modulePath)` \cr
#' ------ \tab ----------- \tab ----- \cr
#' \tab *Temporary Paths* \tab \cr
#' `scratchPath`\tab `file.path(tempdir(), name)` \tab \cr
#' `rasterPath` \tab `file.path(scratchPath, "raster")` \tab sets (`rasterOptions(tmpdir = rasterPath)`) \cr
#' `terraPath` \tab `file.path(scratchPath, "terra")` \tab sets (`terraOptions(tempdir = terraPath)`) \cr
#' ------ \tab ----------- \tab ----- \cr
#' \tab *Other Paths* \tab \cr
#' `logPath` \tab `file.path(outputPath(sim), "log")` \tab sets `options("spades.logPath")` accessible by `logPath(sim)`\cr
#' `tilePath` \tab Not implemented yet \tab Not implemented yet \cr
#' }
#'
#' @export
#' @inheritParams setupProject
#' @param inProject A logical. If `TRUE`, then the current directory is
#' inside the `paths[["projectPath"]]`.
#' @rdname setup
#' @param envir An environment within which to look for objects. If called alone,
#' the function should use its own internal environment. If called from another
#' function, e.g., `setupProject`, then the `envir` should be the internal
#' transient environment of that function.
#' @importFrom Require normPath checkPath
#' @importFrom utils packageVersion
setupPaths <- function(name, paths, inProject, standAlone = TRUE, libPaths = NULL,
updateRprofile = getOption("SpaDES.project.updateRprofile", TRUE),
Restart = getOption("SpaDES.project.Restart", FALSE),
overwrite = FALSE, envir = parent.frame(),
useGit = getOption("SpaDES.project.useGit", FALSE),
verbose = getOption("Require.verbose", 1L), dots, defaultDots, ...) {
envirCur <- environment()
makeUpdateRprofileSticky(updateRprofile)
dotsSUB <- as.list(substitute(list(...)))[-1]
dotsSUB <- dotsToHere(dots, dotsSUB, defaultDots)
messageVerbose(yellow("setting up paths ..."), verbose = verbose, verboseLevel = 0)
pathsSUB <- substitute(paths) # must do this in case the user passes e.g., `list(modulePath = file.path(paths[["projectPath"]]))`
pathsSUB <- checkProjectPath(pathsSUB, name, envir, parent.frame())
paths <- evalSUB(val = pathsSUB, valObjName = "paths", envir = envirCur, envir2 = envir)
paths <- parseFileLists(paths, paths, overwrite = isTRUE(overwrite),
envir = envir, verbose = verbose)
if (!missing(name))
name <- checkNameProjectPathConflict(name, paths)
if (missing(name)) {
name <- basename(paths[["projectPath"]])
}
if (missing(inProject))
inProject <- isInProject(name)
if (is.null(paths[["projectPath"]]))
stop("Please specify paths[[\"projectPath\"]] as an absolute path")
if (!is.null(libPaths)) {
warning("libPaths argument is deprecated. Pass to `paths = list(packagePath = ...)`",
"; it is being ignored", verbose = verbose)
libPaths <- NULL
}
#if (is.null(libPaths) || is.call(libPaths)) {
if (is.null(paths[["packagePath"]])) {
paths[["packagePath"]] <- .libPathDefault(name)
}
if (is.null(paths[["modulePath"]])) paths[["modulePath"]] <- "modules"
isAbs <- unlist(lapply(paths, isAbsolutePath))
toMakeAbsolute <- isAbs %in% FALSE & names(paths) != "projectPath"
if (isTRUE(any(toMakeAbsolute))) {
firstPart <- paste0("^", paths[["projectPath"]], "(/|\\\\)")
alreadyHasProjectPath <- unlist(lapply(paths[toMakeAbsolute], grepl, # value = TRUE,
pattern = firstPart))
if (isTRUE(any(alreadyHasProjectPath)))
paths[toMakeAbsolute][alreadyHasProjectPath] <-
gsub(firstPart, replacement = "", paths[toMakeAbsolute][alreadyHasProjectPath])
}
if (inProject) {
paths[["projectPath"]] <- normPath(".") # checkPaths will make an absolute
}
# on linux, `normPath` doesn't expand if path doesn't exist -- so create first
paths[["projectPath"]] <- checkPath(paths[["projectPath"]], create = TRUE)
paths[["projectPath"]] <- normPath(paths[["projectPath"]]) # expands
if (isTRUE(any(toMakeAbsolute))) {
paths[toMakeAbsolute] <- lapply(paths[toMakeAbsolute], function(x) file.path(paths[["projectPath"]], x))
}
paths <- lapply(paths, checkPath, create = TRUE)
if (!inProject) {
setwd(checkPath(paths[["projectPath"]], create = TRUE))
}
if (is.null(paths$scratchPath)) {
paths$scratchPath <- file.path(tempdir(), name)
}
if (!is.null(paths$scratchPath)) {
paths <- Require::modifyList2(
list(scratchPath = file.path(paths$scratchPath),
rasterPath = file.path(paths$scratchPath, "raster"),
terraPath = file.path(paths$scratchPath, "terra")
),
paths)
}
paths <- Require::modifyList2(
list(cachePath = file.path(paths[["projectPath"]], "cache"),
inputPath = file.path(paths[["projectPath"]], "inputs"),
outputPath = file.path(paths[["projectPath"]], "outputs")
),
paths)
paths <- lapply(paths, normPath)
changedLibPaths <- (!identical(normPath(.libPaths()[1]), paths[["packagePath"]]) &&
(!identical(dirname(normPath(.libPaths()[1])), paths[["packagePath"]])))
needSetLibPathsNow <- !Restart %in% TRUE || inProject %in% TRUE
if (isTRUE(changedLibPaths)) {
deps <- lapply(c("SpaDES.project", "Require"), function(pkg) {
PackagePath <- getNamespaceInfo(pkg, "path")
DESCinLibPaths <- file.path(PackagePath, "DESCRIPTION")
DESCRIPTIONFileDeps(DESCinLibPaths)
})
deps <- unique(c("SpaDES.project", Require::extractPkgName(unlist(deps))))
setupSpaDES.ProjectDeps(paths, verbose = verbose, deps = deps)
needSetLibPaths <- TRUE
} else {
needSetLibPaths <- needSetLibPathsNow
}
prevLibPaths <- .libPaths()
if (needSetLibPaths) {
if (!useGit %in% FALSE) {
# requireNamespace will find usethis in memory when devtools is used, but it fails because other
# deps of usethis are not in the deps of devtools --> can't use `require` b/c CRAN rules
# so need to load before changing .libPaths
deps <- Require::pkgDep("usethis")
depsSimple <- c("usethis", Require::extractPkgName(unname(unlist(deps))))
loaded <- lapply(depsSimple, function(pkg) {
requireNamespace(c(pkg))
})
}
setLPCall <- quote(Require::setLibPaths(paths[["packagePath"]], standAlone = standAlone,
updateRprofile = updateRprofile,
exact = FALSE, verbose = verbose))
prevLibPaths <- if (verbose < 0) {
out <- capture.output(type = "message", ret <- eval(setLPCall))
ret
} else {
eval(setLPCall)
}
if (needSetLibPathsNow %in% FALSE)
on.exit(Require::setLibPaths(prevLibPaths), add = TRUE)
paths[["packagePath"]] <- .libPaths()[1]
}
do.call(setPaths, append(paths[spPaths], list(verbose = verbose)))
messageVerbose(yellow(" done setting up paths"), verbose = verbose, verboseLevel = 0)
paths <- paths[order(names(paths))]
paths[[".previousLibPaths"]] <- prevLibPaths
pathsOrig <- paths
extras <- setdiff(names(paths), spPaths)
attr(paths, "extraPaths") <- paths[extras]
paths
}
#' @export
#' @rdname setup
#'
#' @details
#' `setupFunctions` will source the functions supplied, with a parent environment being
#' the internal temporary environment of the `setupProject`, i.e., they will have
#' access to all the objects in the call.
#'
#' @return
#' `setupFunctions` returns NULL. All functions will be placed in `envir`.
#'
#' @importFrom data.table data.table
#' @examples
#'
#' \dontshow{origDir <- getwd()
#' tmpdir <- Require::tempdir2() # for testing tempdir2 is better}
#' \dontshow{
#' if (is.null(getOption("repos"))) {
#' options(repos = c(CRAN = "https://cloud.r-project.org"))
#' }
#' setwd(tmpdir)
#' }
#' ## simplest case; just creates folders
#' out <- setupProject(
#' paths = list(projectPath = ".") #
#' )
#' # specifying functions argument, with a local file and a definition here
#' tf <- tempfile(fileext = ".R")
#' fnDefs <- c("fn <- function(x) x\n",
#' "fn2 <- function(x) x\n",
#' "fn3 <- function(x) terra::rast(x)")
#' cat(text = fnDefs, file = tf)
#' funHere <- function(y) y
#' out <- setupProject(functions = list(a = function(x) return(x),
#' tf,
#' funHere = funHere), # have to name it
#' # now use the functions when creating objects
#' drr = 1,
#' b = a(drr),
#' q = funHere(22),
#' ddd = fn3(terra::ext(0,b,0,b)))
#' \dontshow{setwd(origDir)}
setupFunctions <- function(functions, name, sideEffects, paths, overwrite = FALSE,
envir = parent.frame(), verbose = getOption("Require.verbose", 1L),
dots, defaultDots, ...) {
envirCur <- environment()
dotsSUB <- as.list(substitute(list(...)))[-1]
dotsSUB <- dotsToHere(dots, dotsSUB, defaultDots)
if (!missing(functions)) {
messageVerbose(yellow("setting up functions..."), verbose = verbose, verboseLevel = 0)
functionsSUB <- substitute(functions) # must do this in case the user passes e.g., `list(fireStart = times$start)`
functions <- evalSUB(functionsSUB, valObjName = "functions", envir = envir, envir2 = envir)
functions <- parseFileLists(functions, paths = paths, namedList = TRUE,
overwrite = isTRUE(overwrite), envir = envir, verbose = verbose)
isFuns <- vapply(functions, is.function, FUN.VALUE = logical(1))
if (any(isFuns))
list2env(functions[isFuns], envir = envir)
messageVerbose(yellow(" done setting up functions"), verbose = verbose, verboseLevel = 0)
}
}
#' @export
#' @rdname setup
#'
#' @details
#' Most arguments in the family of `setup*` functions are run *sequentially*, even within
#' the argument. Since most arguments take lists, the user can set values at a first
#' value of a list, then use it in calculation of the 2nd value and so on. See
#' examples. This "sequential" evaluation occurs in the `...`, `setupSideEffects`, `setupOptions`,
#' `setupParams` (this does not work for `setupPaths`) can handle sequentially
#' specified values, meaning a user can
#' first create a list of default options, then a list of user-desired options that
#' may or may not replace individual values. This can create hierarchies, *based on
#' order*.
#'
#' @return
#' `setupSideEffects` is run for its side effects (e.g., web authentication, custom package
#' options that cannot use `base::options`), with deliberately nothing returned to user.
#' This, like other parts of this function, attempts to prevent unwanted outcomes
#' that occur when a user uses e.g., `source` without being very careful about
#' what and where the objects are sourced to.
#'
#'
#' @importFrom data.table data.table
setupSideEffects <- function(name, sideEffects, paths, times, overwrite = FALSE,
envir = parent.frame(), verbose = getOption("Require.verbose", 1L),
dots, defaultDots, ...) {
envirCur <- environment()
dotsSUB <- as.list(substitute(list(...)))[-1]
dotsSUB <- dotsToHere(dots, dotsSUB, defaultDots)
if (!missing(sideEffects)) {
messageVerbose(yellow("setting up sideEffects..."), verbose = verbose, verboseLevel = 0)
sideEffectsSUB <- substitute(sideEffects) # must do this in case the user passes e.g., `list(fireStart = times$start)`
sideEffects <- evalSUB(sideEffectsSUB, valObjName = "sideEffects", envir = envirCur, envir2 = envir)
if (!is.character(sideEffects)) { # this is because I wrote this second;
tf <- tempfile()
writeLines(format(sideEffects[-1]), con = tf)
sideEffects <- tf
}
sideEffects <- parseFileLists(sideEffects, paths, namedList = FALSE,
overwrite = isTRUE(overwrite), envir = envir, verbose = verbose)
messageVerbose(yellow(" done setting up sideEffects"), verbose = verbose, verboseLevel = 0)
}
}
#' @export
#' @rdname setup
#'
#' @details
#' `setupOptions` can handle sequentially specified values, meaning a user can
#' first create a list of default options, then a list of user-desired options that
#' may or may not replace individual values. Thus final values will be based on the
#' order that they are provided.
#'
#' @return
#' `setupOptions` is run for its side effects, namely, changes to the `options()`. The
#' list of modified options will be added as an attribute (`attr(out, "projectOptions")`),
#' e.g., so they can be "unset" by user later.
#'
#'
#' @importFrom data.table data.table
setupOptions <- function(name, options, paths, times, overwrite = FALSE, envir = parent.frame(),
verbose = getOption("Require.verbose", 1L), dots, defaultDots,
useGit = getOption("SpaDES.project.useGit", FALSE),
updateRprofile = getOption("SpaDES.project.updateRprofile", TRUE),
...) {
makeUpdateRprofileSticky(updateRprofile)
dotsSUB <- as.list(substitute(list(...)))[-1]
dotsSUB <- dotsToHere(dots, dotsSUB, defaultDots)
newValuesComplete <- oldValuesComplete <- NULL
updates <- NULL
if (!missing(options)) {
messageVerbose(yellow("setting up options..."), verbose = verbose, verboseLevel = 0)
preOptions <- base::options() # need prefix or else greedy evaluation occurs on the `options()` as if it is the arg
optionsSUB <- substitute(options) # must do this in case the user passes e.g., `list(fireStart = times$start)`
envirCur <- environment()
options <- evalSUB(optionsSUB, valObjName = "options", envir = envirCur, envir2 = envir)
# post check
# if (isTRUE(try(any(grepl("^options$", eval(optionsSUB, envir = envir)[[1]])), silent = TRUE))) {
# warning("It looks like the options argument is passed options(...); please use list(...)")
# }
if (missing(paths)) {
pathsSUB <- substitute(paths) # must do this in case the user passes e.g., `list(modulePath = paths$projectpath)`
pathsSUB <- checkProjectPath(pathsSUB, name, envir = envirCur, envir2 = envir)
paths <- setupPaths(paths = pathsSUB, defaultDots = defaultDots,
updateRprofile = updateRprofile,
useGit = useGit, verbose = verbose - 2)#, inProject = TRUE, standAlone = TRUE, libPaths,
}
options <- parseFileLists(options, paths, overwrite = isTRUE(overwrite),
envir = envir, verbose = verbose)
postOptions <- base::options()
newValues <- oldValues <- list()
if (length(options)) {
newValuesComplete <- options
oldValuesComplete <- Map(nam = names(options), function(nam) NULL)