-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata_table_import.R
32 lines (26 loc) · 1.2 KB
/
data_table_import.R
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
library(argparser)
library(AnvilDataModels)
library(readr)
argp <- arg_parser("import")
argp <- add_argument(argp, "--table_files", help="2-column tsv file with (table name, table tsv file)")
argp <- add_argument(argp, "--model_file", help="json file with data model")
argp <- add_argument(argp, "--overwrite", flag=TRUE, help="overwrite existing rows in tables")
argp <- add_argument(argp, "--workspace_name", help="name of AnVIL workspace to import data to")
argp <- add_argument(argp, "--workspace_namespace", help="namespace of AnVIL workspace to import data to")
argv <- parse_args(argp)
# argv <- list(table_files="testdata/table_files.tsv",
# model_file="testdata/data_model.json",
# overwrite=FALSE)
# identify table files
table_files <- read_tsv(argv$table_files, col_names=c("names", "files"), col_types="cc")
# read data model
if (!is.na(argv$model_file)) {
model <- json_to_dm(argv$model_file)
} else {
model <- NULL
}
# read tables
tables <- read_data_tables(table_files$files, table_names=table_files$names)
# import tables
anvil_import_tables(tables, model=model, overwrite=argv$overwrite,
namespace=argv$workspace_namespace, name=argv$workspace_name)