scoping - Include source code to function from external file in R -
scoping - Include source code to function from external file in R -
i have standard info analysis procedure need run on various (~50 datasets). have been developing time , got point turn function takes dataset , spits out sensible table each dataset. however, procedure done spans on 4 script files , far have used source 1 run it, seems seems impossible function.
i have next problem:
foo <- function(data) { <- somevariable source("..somefile..") #the code in there uses a, not in workspace... .. go on .. } the code crashes when run on dataset.
is there way (command) copy-paste commands other files while compiling (don't know how phone call differently, though not real compiling) function? know can copy-paste myself, rather not, because various steps include neural-networks , arfima estimations maintain in separate files sake of readability of code. anyway function after copy-paste 200 lines of code, not user friendly...
thx
i'd suggest starting minimal illustration sense of writing function entails, how load function r using source(), how utilize arguments, , how phone call function. after doing that, more evident go next.
to reply question, if script includes 200 lines of code , 1 thing (that is, 1 function), should thinking wrapping function, yes. increment user friendliness rather decrease since scripts can include 1 line (the function call) rather original 200 lines of code.
r scoping reproducible-research
Comments
Post a Comment