Abstract
In the last chapter a simple function was created within a call to the sapply function. In this chapter we explore user-defined functions more broadly and write a function for producing a keyword in context (KWIC) list.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
See Firth, John Rupert. “A Synopsis of Linguistic Theory, 1930–1955.” In Studies in Linguistic Analysis. Oxford: Blackwell (1957): 1–32.
- 2.
It is worth noting that the name(s) we assign to the arguments inside the parentheses have a scope that is limited to the function; these variable names do not persist or exist outside of the function, and they will not overwrite a variable with the same name that may exist outside of the function. That said, it is best to avoid duplication of variable names. Notice that I have named the argument file.name.v instead of files.v. For an example in code, see Appendix B.
- 3.
Remember that, you can run a whole block of code by selecting it all in the editing window and then hitting the control and return keys at the same time.
- 4.
In R you do not always have to explicitly call return. By default R will return whatever object is in the last line of the function. Explicitly calling return, however, often makes it easier to read and debug your function code.
- 5.
If you try this now, you’ll see that you are actually getting Project Gutenberg’s boilerplate words, but you get the idea.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2014 Springer International Publishing Switzerland
About this chapter
Cite this chapter
Jockers, M.L. (2014). Do It KWIC. In: Text Analysis with R for Students of Literature. Quantitative Methods in the Humanities and Social Sciences. Springer, Cham. https://doi.org/10.1007/978-3-319-03164-4_8
Download citation
DOI: https://doi.org/10.1007/978-3-319-03164-4_8
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-03163-7
Online ISBN: 978-3-319-03164-4
eBook Packages: Mathematics and StatisticsMathematics and Statistics (R0)