spinStory: Build A Recursive Story From Normal Text

Description Usage Arguments Value Examples

Description

This function takes a list of infiles (infilenames), a dictionary, and a list of outfilenames. It will search each line of the infiles for possible trigger words in "val" column of "mydic", and substitute in the correct key value for those words.

Usage

1
spinStory(infilenames, mydic, outfilenames = "", exec = F)

Arguments

infilenames

A list of input files, with appropriate file paths, to read into the program.

mydic

A dictionary of keys and values to look up. Needs "key" and "val" columns. If there are repeat values, the first one only will be used by the program, and there will be no warning.

outfilenames

A list of names for the resulting text. Good practice is to place into a separate folder instead of rewriting, in case something bad happens.

exec

By default, this is FALSE. If TRUE, the program will write the resulting files to their intended places.

Value

This function returns a list with the transformed story files. This may be a very, very large list, so be sure to execute this with a variable assignment.

Examples

1
2
3
4
cat("The dog walked in the park.", "The End.", sep="\n", file="sampleStory.txt")
myDic <- data.frame(key=c("<animal>", "<animal>", "<walk>", "<walk>", "<park>"),
                   val=c("dog", "cat", "ran", "walked", "park"), stringsAsFactors=F)
spinStory("sampleStory.txt", myDic, "rawr.txt" )

ecology-rocks/grammaR documentation built on May 15, 2019, 7:58 p.m.