-4

I have two R scripts. The first reads csv files, cleans the data, checks for mathematical errors and corrects them ("errorcheck.R"). The second script gets the clean data from the first, combines column names, expressions and values and creates csv files ("createTables.R"). Originally, the first script was created for importing 5 csv files. But for some projects I might have only 4 or 3 csv files to import, which is fine for the final output. But that throws me an error and when I try to source the first script from the second script, I don't get the clean csv files. How can I source the clean datasets from the first script, even with errors? The errors come only from calling csv files that don't exist.

I'm not sure if this is the same question as: Is there a way to `source()` and continue after an error? Can I have some ideas on this please?

Thanks in advance

Community
  • 1
  • 1
Dimitra
  • 3
  • 4

1 Answers1

0

I am not sure if this serves your answer or not:

Situation: 1. According to your description, your first scripts is made for static input of length of 5. (i.e. 5 .csv file input)

Solution: I don't know how you take the input of .csv files in first script. I suggest to create a vector of string and pass that to first script and calculate the length of vector to decide how many times your operation should run. Now, the input can be of any length. So, You can effectively handle any range of .csv files rather than only for 5. Try avoiding hard-coding.

Please let me know if this answer your question. If you face any diffculty just let me know.

BoyInDaBox89
  • 417
  • 5
  • 16
  • Each of the csv files contains different kind of data, i.e. water, air etc. therefore, they're checked for different errors. I might need to create a list or a vector, as you suggested, with all the csv files and one list to match the different error checking processes. Thanks a lot for your help! – Dimitra Jan 19 '17 at 13:57