Learn R Programming

ds4psy (version 0.2.0)

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

Description

read_ascii parses text (from a file or from user input in Console) into a tibble 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 tibble 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 here package is used to determine the (absolute) file path.

See Also

plot_text for a corresponding plot function.

Other text functions: capitalize(), caseflip(), count_char(), l33t_rul35, 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