0

For example, if I was reading in multiple files from excel in which some were to be read without skipping first row and some weren't, and I wanted to code this in how would I do it?

additional_read_param <- "skip = 1"

read_excel("mtcars.xlsx", sheet = 1, additional_read_param )

How do I actually get this to work?

  • 2
    You can use `eval(parse` – akrun Sep 17 '19 at 19:08
  • Ahh, I see - so you construct your function call as a string and pass it into `eval(parse( string here ) ) `. Is this the *only* way to do it? Is there a way to have the function be able to process parameters passed as string? I got it working using the eval-parse method – random_passerby123 Sep 17 '19 at 19:42
  • Another option is to have a named `list` and pass the parameters to the function in `do.call` – akrun Sep 17 '19 at 19:43
  • How would I pass the string `skip = 1` or variation of it into a list for do.call? `do.call(read_excel, list(file = file_path, sheet = 1)` works but variations of trying to add `additional_read_param` to it doesn't work – random_passerby123 Sep 17 '19 at 19:53
  • Let's say I have 10 files. 8 of them I do not want read with `skip = 1`, 2 of them I do. I could do an if/else and call 2 different `read_excel` but I'm interested in a way that doesn't requiring double the code. – random_passerby123 Sep 17 '19 at 20:49

1 Answers1

-1

I'm not sure if this will work but you can try read_excel("mtcars.xlsx", sheet = 1, paste(additional_read_param))

JRN
  • 213
  • 1
  • 10
  • 1
    Did you test this before you posted it as an answer? – AkselA Sep 17 '19 at 19:16
  • 1
    If you're making a suggestion ("not sure if this will work") rather than a full answer, that's better done in comments once you have the rep for it – camille Sep 17 '19 at 19:30
  • It work for me but I'm no sure if it the same for random_passerby123 – JRN Sep 17 '19 at 19:51