0

I've written a user-friendly script for someone who has no R/coding experience, so I stored all the core work of what it's supposed to do into a .R file and all they have to do is run source('file.R'). However, within my functions I do have arguments that when run individually, could be changed with different outcomes, for example print something or not.

When calling source(), is it possible to also pass some of those arguments to change them from their defaults as defined in the function? And if so, how?

I tried to simply defining them before calling source(), to no avail. I am successfully passing a vector with values to be used (colors for plotting), so I'm not sure what I'm missing.

1
  • What exactly is in the file you are sourcing? Ideally you'd define functions in that file that the user can easily call with whatever parameters they want. How are these parameters you want to change defined? Commented Nov 16, 2022 at 18:08

1 Answer 1

1

the source function allow you to load a script which may contain one or many functions. So you can load your script after that run the function with desired arguments. something like:

source('file.R')
my_function(arg1,arg2)

take a look here for an example :https://www.statology.org/source-function-in-r/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.