Learn R Programming

ds4psy (version 0.4.0)

read_ascii: read_ascii parses text (from a file) into a table.

Description

read_ascii parses text (from a file or from user input in Console) into a table that contains a row for each character.

Usage

read_ascii(file = "", flip_y = FALSE)

Arguments

file

The text file to read (or its path). If file = "" (the default), scan is used to read user input from the Console. If a text file is stored in a sub-directory, enter its path and name here (without any leading or trailing "." or "/"). Default: file = "".

flip_y

Boolean: Should y-coordinates be flipped, so that the lowest line in the text file becomes y = 1, and the top line in the text file becomes y = n_lines? Default: flip_y = FALSE.

Details

read_ascii creates a data frame with 3 variables: Each character's x- and y-coordinates (from top to bottom) and a variable char for the character at this coordinate.

The getwd function is used to determine the current working directory. This replaces the here package, which was previously used to determine an (absolute) file path.

See Also

plot_text for a corresponding plot function.

Other text objects and functions: Umlaut, capitalize(), caseflip(), cclass, count_chars(), count_words(), l33t_rul35, metachar, text_to_sentences(), text_to_words(), transl33t()

Examples

Run this code
# NOT RUN {
## Create a temporary file "test.txt":
# cat("Hello world!", "This is a test.", 
#     "Can you see this text?", 
#     "Good! Please carry on...", 
#     file = "test.txt", sep = "\n")

## (a) Read text (from file): 
# read_ascii("test.txt")
# read_ascii("test.txt", flip_y = TRUE)  # y flipped

# unlink("test.txt")  # clean up (by deleting file).
 
# }
# NOT RUN {
## (b) Read text (from file in subdir):
# read_ascii("data-raw/txt/ascii.txt")  # requires txt file

## (c) Scan user input (from console):
# read_ascii()
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab