get_abbrtable: Create an abbreviation table by merging user-provided and...

View source: R/get_abbrtable.R

get_abbrtableR Documentation

Create an abbreviation table by merging user-provided and system tables

Description

This function processes a user-provided abbreviation table and optionally merges it with a system abbreviation table. The user table can be provided as a file path, data.frame, or data.table. The system table is included by default but can be excluded.

Usage

get_abbrtable(user_table = NULL, use_sys_table = TRUE)

Arguments

user_table

A user-provided abbreviation table. It can be a file path (string), a data.frame, or a data.table. The table must contain columns journal_lower and journal_abbr. Default is NULL.

use_sys_table

Logical. Whether to include the system abbreviation table (abbrtable_sys) in the merged result. Default is TRUE.

Details

The function first processes the user-provided table by checking its type:

  • If it's a file path, it reads the file using data.table::fread.

  • If it's a data.frame, it is converted to a data.table.

  • If it's already a data.table, no conversion is needed.

After processing the user table, the system table (abbrtable_sys) is optionally included in the final merged table. Duplicate entries based on journal_lower are removed.

Value

A data.table containing the merged abbreviation table, with any duplicates (by journal_lower) removed. The resulting table contains two columns: journal_lower and journal_abbr.

Examples

# Example 1: Provide a user table as a CSV file path and merge with system table
user_table_path <- system.file("extdata", "myabbr.csv", package = "journalabbr", mustWork = TRUE)
abbr_table <- get_abbrtable(user_table = user_table_path, use_sys_table = TRUE)

# Example 2: Provide a user table as a data.frame
user_df <- data.frame(journal_lower = c("example journal", "sample journal"),
                      journal_abbr = c("EJ", "SJ"))
abbr_table <- get_abbrtable(user_table = user_df, use_sys_table = FALSE)

# Example 3: Use only the system table
abbr_table <- get_abbrtable(use_sys_table = TRUE)

abbr_table <- get_abbrtable(user_table=NULL, use_sys_table = FALSE)

zoushucai/journalabbr documentation built on Dec. 6, 2024, 4:41 p.m.