import_table: Import a raw data file into table in stock database

Description Usage Arguments Details Value Functions See Also

Description

Generic function to import a raw data into target table in stock database.

Usage

 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
import_table(
  stock_db,
  input_file,
  input_template = NULL,
  input_type = c("csv", "txt"),
  input_dir = NULL,
  start_index = 2L,
  target_table = NULL,
  ignore_problems = TRUE,
  log_dir = "./log",
  ...
)

## S4 method for signature 'gta_db'
import_table(
  stock_db,
  input_file,
  input_template = NULL,
  input_type = c("csv", "txt"),
  input_dir = NULL,
  start_index = 2L,
  target_table = NULL,
  ignore_problems = TRUE,
  log_dir = "./log",
  ...
)

Arguments

stock_db

A stock database object to operate.

input_file

A character of name or path of input data file, which could use regular expression to import multiple files into a table, e.g. test[0-9]*.txt" will read files like test.txt, test1.txt,..., test9.txt..., etc., the files ware queued in ascending alphabet order.

input_template

A character of name of input template file. Default NULL means use as input_file when reading single files or the first file in input_file when reading multiple files.

input_type

Format of input file, e.g. "txt", "csv".

input_dir

Working dir of input file, if NULL, use dir of input file as working dir, by default NULL,

start_index

Start index of first line of actual records in data file, by default 2L, which means first line is header and actual data starts from second lines.

target_table

Name of target table in stock db, if NULL, use basename input_file as target table , by default NULL,

ignore_problems

Whether to ignore problems when covert data, if TRUE, continue to import data but log problems into log file, otherwise abort importing process. By default TRUE.

log_dir

Path of log dir for saving problem log file, by default"./log", if the log path doesn't existed, it will be created.

...

Extra arguments to be passed to methods.

Details

Import process include two phrases:

  1. Convert raw data into R data type.

  2. Transfer R data into table in database.

Any problem in converting raw data will be logged in log file in log dir, e.g. "input_file(YYYY-MM-DD).csv"

Value

TRUE if success, else FALSE.

Functions

See Also

Other data management: clear_tables(), convert_import_file(), get_datasource(), process_files(), read_import_file(), ttm_financial_report(), update_db(), write_import_file()


chriszheng2016/zstmodelr documentation built on June 13, 2021, 8:59 p.m.