5
5
# ' specific project and task/game combination. Further pre-processing on the
6
6
# ' fetched data can also be added if requested.
7
7
# '
8
- # ' @param params A [data.frame] or [list] contains the parameters to be bound to
9
- # ' the query. Default templates require specifying `organization_name` and
10
- # ' `project_name`, in that order. If `contents` template is specified without
11
- # ' any parameters, set it as empty vector or `NULL`. If `contents` argument is
12
- # ' specified, this argument is omitted.
8
+ # ' @param params,contents Used as the configuration of data fetching. These two
9
+ # ' arguments are mutually exclusive. If `params` is specified, it will be used
10
+ # ' as parameters to be bound to the query, see [DBI::dbBind()] for more
11
+ # ' details. The default template requires specifying `organization_name` and
12
+ # ' `project_name`, in that order. If `contents` is specified, it should be a
13
+ # ' [data.frame] and will be used directly as the configuration of data
14
+ # ' fetching. Note `contents` should at least contain `project_id` and
15
+ # ' `game_id` names.
13
16
# ' @param ... For future usage. Should be empty.
14
- # ' @param contents The contents structure used as the configuration of data
15
- # ' fetching. It is typically automatically fetched from database based on the
16
- # ' `contents` template in `templates`. If not `NULL`, it will be used directly
17
- # ' and ignore that specified in `templates`. Note `contents` should at least
18
- # ' contains `project_id` and `game_id` names.
19
17
# ' @param what What to fetch. There are basically two types of data, i.e., raw
20
18
# ' data and scores. The former is the logged raw data for each trial of the
21
19
# ' tasks/games, while the latter is the scores calculated by iQuizoo server.
29
27
# ' done. If set as "none", neither will be done. If `what` is "scores", this
30
28
# ' argument will be ignored.
31
29
# ' @param combine Specify which targets to be combined. Note you should only
32
- # ' specify names from `c("scores", "raw_data", "raw_data_parsed",
33
- # ' "indices")`. If `NULL`, none will be combined.
30
+ # ' specify names from `c("scores", "raw_data", "raw_data_parsed", "indices")`.
31
+ # ' If `NULL`, none will be combined.
34
32
# ' @param templates The SQL template files used to fetch data. See
35
33
# ' [setup_templates()] for details.
36
34
# ' @param check_progress Whether to check the progress hash. Set it as `FALSE`
37
35
# ' if the project is finalized.
38
36
# ' @return A list of target objects.
39
37
# ' @export
40
- tar_prep_iquizoo <- function (params , ... ,
41
- contents = NULL ,
38
+ tar_prep_iquizoo <- function (params , contents , ... ,
42
39
what = c(" raw_data" , " scores" ),
43
40
action_raw_data = c(" all" , " parse" , " none" ),
44
41
combine = NULL ,
45
42
templates = setup_templates(),
46
43
check_progress = TRUE ) {
47
44
check_dots_empty()
48
45
check_templates(templates )
46
+ contents <- switch (check_exclusive(params , contents ),
47
+ params = fetch_iquizoo_mem()(
48
+ read_file(templates $ contents ),
49
+ params = unname(
50
+ if (! is_empty(params )) as.list(params )
51
+ )
52
+ ),
53
+ contents = {
54
+ stopifnot(
55
+ " `content` must be a `data.frame`." =
56
+ is.data.frame(contents )
57
+ )
58
+ contents
59
+ }
60
+ )
49
61
what <- match.arg(what , several.ok = TRUE )
50
62
action_raw_data <- match.arg(action_raw_data )
51
63
if (! is.null(combine ) && ! all(combine %in% objects())) {
@@ -54,14 +66,6 @@ tar_prep_iquizoo <- function(params, ...,
54
66
class = " tarflow_bad_combine"
55
67
)
56
68
}
57
- if (is.null(contents )) {
58
- contents <- fetch_iquizoo_mem()(
59
- read_file(templates $ contents ),
60
- params = unname(
61
- if (! is_empty(params )) as.list(params )
62
- )
63
- )
64
- }
65
69
if (nrow(contents ) == 0 ) {
66
70
cli :: cli_abort(
67
71
" No contents to fetch." ,
0 commit comments