Functions to read and write table or text files conveniently. Complements the new CodeAndRoll2.
- The underlying
gdata
removedread.xls
, and this is resolved inv1.0.0
by usingopenxlsx
. - As of 11/2023 you may need
install_github(repo = "vertesy/ReadWriter@main")
instead ofinstall_github(repo = "vertesy/ReadWriter")
to install the package on some platforms.
Install directly from GitHub via devtools with one R command:
# install.packages("devtools"); # If you don't have it.
require("devtools")
devtools::install_github(repo = "vertesy/Stringendo", upgrade = F)
devtools::install_github(repo = "vertesy/ReadWriter")
"As of 11/2023 you may need:"
devtools::install_github(repo = "vertesy/ReadWriter@main")
...then simply load the package:
require("ReadWriter")
Alternatively, you simply source it from the web. This way function help will not work, and you will have no local copy of the code on your hard drive.
source("https://raw.githubusercontent.com/vertesy/ReadWriter/main/R/ReadWriter.R")
If you encounter a bug, something doesn't work or unclear, please let me know by raising an issue on ReadWriter – Please check if it has been asked.
Updated: 2023/11/24 16:40
Convert a Column to Row Names in a Tibble or DataFrame. Converts the first column (or a specified column) of a dataframe or tibble into row names. This function differs from tibble::column_to_rownames
in that it takes column names or inices and it offers the option to sanitize row names using make.names
, provides a warning if there are duplicated values in the row name column
FirstCol2RowNames. Set First Col to Row Names
FirstCol2RowNames.as.df. Set First Col to Row Names
read.simple.vec. Read each line of a file to an element of a vector (read in new-line separated values, no header!).
read.simple. It is essentially read.table() with file/path parsing.
read.simple_char_list. Read in a file.
read.simple.table. Read in a file. default: header defines colnames, no rownames. For rownames give the col nr. with rownames, eg. 1 The header should start with a TAB / First column name should be empty.
read.simple.tsv. Read in a file with excel style data: rownames in col1, headers SHIFTED. The header should start with a TAB / First column name should be empty.
read.simple.csv. Read in a file with excel style data: rownames in col1, headers SHIFTED. The header should start with a TAB / First column name should be empty.
read.simple.ssv. Space separeted values. Read in a file with excel style data: rownames in col1, headers SHIFTED. The header should start with a TAB / First column name should be empty.
read.simple.tsv.named.vector. Read in a file with excel style named vectors, names in col1, headers SHIFTED. The header should start with a TAB / First column name should be empty.
Read a multi-sheet XLSX easily. Reads specified sheets from an XLSX file into a list of data frames. It allows customization of column names, row names, and trimming of white spaces.
write.simple. Write out a matrix-like R-object to a file with as tab separated values (.tsv). Your output filename will be either the variable's name. The output file will be located in "OutDir" specified by you at the beginning of the script, or under your current working directory. You can pass the PATH and VARIABLE separately (in order), they will be concatenated to the filename.
write.simple.vec. Write out a vector-like R-object to a file with as newline separated values (.vec). Your output filename will be either the variable's name. The output file will be located in "OutDir" specified by you at the beginning of the script, or under your current working directory. You can pass the PATH and VARIABLE separately (in order), they will be concatenated to the filename.
write.simple.tsv. Write out a matrix-like R-object WITH ROW- AND COLUMN- NAMES to a file with as tab separated values (.tsv). Your output filename will be either the variable's name. The output file will be located in "OutDir" specified by you at the beginning of the script, or under your current working directory. You can pass the PATH and VARIABLE separately (in order), they will be concatenated to the filename.
write.simple.append. Append an R-object WITHOUT ROWNAMES, to an existing .tsv file of the same number of columns. Your output filename will be either the variable's name. The output file will be located in "OutDir" specified by you at the beginning of the script, or under your current working directory. You can pass the PATH and VARIABLE separately (in order), they will be concatenated to the filename.