Search code examples
rtext-miningquanteda

Change the length of ContextPre and ContextPost in Quanteda KWIC


Is there a way to increase the number of words appearing before and after the keyword in Quanteda kwic function?

I've tried by changing the numeric value in:

options(width = 200)

but it didn't work. @KenBenoit


Solution

  • options(width) affects the number of text columns displayed by the R interpreter. You want the window argument to kwic():

    >  kwic(data_corpus_inaugural, "war against")
                                                   contextPre     keyword                         contextPost
     [1857-Buchanan, 2933:2934] advantage of the fortune of [ war against ] a sister republic, we
     [1901-McKinley, 2284:2285]         . We are not waging [ war against ] the inhabitants of the Philippine
     [1901-McKinley, 2299:2300]  portion of them are making [ war against ] the United States. By
     [1901-McKinley, 2413:2414]    used when those who make [ war against ] us shall make it no
    [1933-Roosevelt, 1851:1852]   Executive power to wage a [ war against ] the emergency, as great
    >  kwic(data_corpus_inaugural, "war against", window=7)
                                                           contextPre     keyword                                  contextPost
     [1857-Buchanan, 2933:2934] to take advantage of the fortune of [ war against ] a sister republic, we purchased these
     [1901-McKinley, 2284:2285]      be deceived. We are not waging [ war against ] the inhabitants of the Philippine Islands.
     [1901-McKinley, 2299:2300]      . A portion of them are making [ war against ] the United States. By far the
     [1901-McKinley, 2413:2414]  needed or used when those who make [ war against ] us shall make it no more.
    [1933-Roosevelt, 1851:1852]   - broad Executive power to wage a [ war against ] the emergency, as great as the