I have an R script that takes in a dataset and a list of keywords. It then creates a plot based on how many times each of the keywords occur in the dataset, and saves it as a png image. Now, I want to make the keyword list dynamic, i.e. I want the keywords to be user inputs. Somehow, in the environment I am working in, it so happens that once the user has entered a list of keywords, I execute the R script and present the user with the plot. Now when the user enters some more keywords, they are appended to the previous list and since the complete list of keywords are sent to the R script, it performs the complete task again. It is obvious that it is doing a lot of unnecessary work of finding the keywords that were there in the first run too.
For example, in the first run, list of keywords:- "One", "Two", "Three". In the second run, list of keywords:- "One", "Two", "Three", "Four", "Five", "Six"
In the second run, it wastes a lot of time working on keywords "One", "Two" and "Three". Since the dataset will be huge and so will the number of keywords, it will take a lot of time to execute. My question is, is there a way I could prevent this, retain the previous plot and modify the previous plot to present the new keywords as well?