read_color_code: Read color codes from a given file

View source: R/mapper_vis.R

read_color_codeR Documentation

Read color codes from a given file

Description

read_color_code reads a file with given group names and color codes and returns a dataframe with group names and color codes that can be accepted by visualization functions.

Usage

read_color_code(file, header = FALSE, sep = "\t")

Arguments

file

the name of the file which the data are to be read from. Each row of the table appears as one line of the file. If it does not contain an absolute path, the file name is relative to the current working directory, getwd(). Tilde-expansion is performed where supported. This can be a compressed file (see file).

Alternatively, file can be a readable text-mode connection (which will be opened for reading if necessary, and if so closed (and hence destroyed) at the end of the function call). (If stdin() is used, the prompts for lines may be somewhat confusing. Terminate input with a blank line or an EOF signal, Ctrl-D on Unix and Ctrl-Z on Windows. Any pushback on stdin() will be cleared before return.)

file can also be a complete URL. (For the supported URL schemes, see the ‘URLs’ section of the help for url.)

header

a logical value indicating whether the file contains the names of the variables as its first line. If missing, the value is determined from the file format: header is set to TRUE if and only if the first row contains one fewer field than the number of columns.

sep

the field separator character. Values on each line of the file are separated by this character. If sep = "" (the default for read.table) the separator is ‘white space’, that is one or more spaces, tabs, newlines or carriage returns.

Details

The given files should contain two columns. The first column should consist of the names of the labels, and the second column should contain standard Hex color codes.

Value

A dataframe that contains color codes for samples from different groups. The first column consists of names of the groups and the second column contains the coresponding color codes.

Examples

test1 <- data.frame(c('a','b','c'), c("#f97f6c", "#6dcff6", "#fdbc4b"))
tf <- tempfile()
write.table(test1, tf, row.names = FALSE, col.names = FALSE, sep = "\t")

check_color_code(read_color_code(tf))
unlink(tf)

TianshuFeng/SemiMapper documentation built on Sept. 16, 2022, 10:26 p.m.