A function for getting string matches and the context in which they occur.
Arguments
- match
Character string to be matched. For multiple strings, please use "|" as a separator.
- v
Text vector or annotated data frame.
- level
At which text level do you want matches to be returned? Defaults to "sentences". Options are sentences, words, and paragraph.
- n
Number of sentences or words matched before and after string match. Defaults to 1. That is, one word or one sentence before, and after, string match. For paragraphs, n is always set to one.
Examples
# \donttest{
extract_context(match = "war|weapons of mass destruction|conflict|NATO|peace",
v = US_News_Conferences_1960_1980$text[100],
level = "sentences", n = 2)
#> [[1]]
#> [1] " We are not necessarily associating you with that, Miss Thomas. [Laughter],In voting to sustain the President's veto, the Members of the Senate vetoed longer gas lines and vetoed nationwide rationing.,What we must now do is to move forward on the various measures that I have proposed that will accomplish the goal that this bill mistakenly was aimed to accomplish, and that is to get down the price of gasoline. That can only be done by increasing the supplies of gasoline and other types of energy.,That is why I trust that the Congress will move expeditiously on the proposals that I have made for the deregulation of natural gas, for doing something with regard to those measures in the field in the environment which restrict the production of coal, which could greatly alleviate the energy crisis--to the extent it is still a crisis--to go forward also on the Elk Hills production and exploration for oil in that Federal area, and in the longer sense, to go forward with the various proposals that we have made for organization in the energy field, which will allow us to develop our nuclear power, new sources of energy, and to achieve the goal we all want to achieve, of independence for the United States for energy by at least, and preferably before, the year 1980."
#> [2] "] Q. Mr. President, some economists are warning that consumers are becoming so disenchanted with inflation that they may reduce their spending drastically later this year as sort of a consumer revolt. Do you share this fear, and what encouragement do you have for consumers in this time of the worst inflation in 25 years?,THE PRESIDENT. First, with regard to the inflation, as I pointed out just a week ago in a press conference, there are two major factors that have caused it."
#> [3] " In fact, they have been responsible for two-thirds of the inflation.,One is energy--increased prices for energy--and the second is food.,Now, the back of the energy crisis has been broken, and as we go toward the end of the year, I would say toward the middle of the year we will see the prices of energy being kept in check and, we trust, even moving downward.,As far as food is concerned, if the Department of Agriculture's reports are accurate and if the weather holds up properly, we will have a record food crop, particularly a record wheat crop, and that will tend to bring the price upsurge in food under control.,And so, as far as the future is concerned for inflation, while it is still a very sticky problem and will remain so for some time, we see the problem being much less difficult as the year goes on than it is at the present time."
#> [4] " I saw a report, as you may have, this afternoon from the University of Pennsylvania, where they indicated that they thought we were either in, or headed for, a recession.,I state again, based on my consultation with my own economic advisers and also consultation with people outside the Government, the best advice I can get, that there will not be a recession in 1974.,I think that progress that we will make on the energy front, progress that we are going to make on the food front, and also the continued strength in other areas of the economy will mean that the last half of the year will see an upward turn in the economy.,I believe, in other words, that we are not going to see a situation where we have rising prices as well as rising unemployment, which, of course, would mean a recession. That, of course, is a projection that I give, based not simply on my knowledge but based on all of the facts that I am able to get from the economists who should know something about it."
#> [5] ",For example, I found that between 1964 and 1966 the Republicans won 5 and the Democrats won 7 Congressional seats, and yet the Republicans won 47 seats in 1966.,Also, reflecting to the past, after General Eisenhower's landslide victory in 1956, we lost 47 seats in the House just 2 years later in 1958 because of a recession. And after President Johnson's landslide victory in 1964, his party lost 47 seats in the House, just 2 years later, because of a war.\nThis year, we are not going to have a war. We are going to be making further progress toward peace--at least that is our goal, and I think we will achieve it-and we are not going to have a recession."
#> [6] ",Now, how would you answer that thesis?,THE PRESIDENT. Well, on the contrary, I think that the use of immunity for any major White House employee would be highly improper. After all, someone who has the position of Counsel to the President should come forward and testify as to everything that he knows, and he should not require as the price for telling the truth getting immunity. That was my view then; it is my view now.,I should also point out that in the case of Mr."
#> [7] " Mr. President, you met this week with the leaders of the Appropriations Committee partly in regard to the defense budget. And later, Senator McClellan said he would favor slashing $3 billion from that budget, which as you know is nearly $90 billion, higher than in wartime. Could you tell us if you think that is a dangerous cut, and if so, why?,THE PRESIDENT. Senator McClellan told me that he wanted to cut the budget by $3 billion, and he is a watchdog of the treasury, and incidentally, so is Congressman Mahon."
#>
# }