Skip to main content
  • 9003 Accesses

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 49.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 64.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    See Firth, John Rupert. “A Synopsis of Linguistic Theory, 1930–1955.” In Studies in Linguistic Analysis. Oxford: Blackwell (1957): 1–32.

  2. 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. 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. 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. 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

Authors

Rights and permissions

Reprints 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

Publish with us

Policies and ethics