Application Functions in Multiple Source Files

36 views
Skip to first unread message

Dario Strbenac

unread,
Aug 31, 2015, 1:59:05 AM8/31/15
to Shiny - Web Framework for R
The user code needs to be in server.R or ui.R or global.R. To be modular and assist in maintenance, it is nice to have short source files. Is it possible to have the code in multiple R files with filenames that I choose, if the application will have lots of functions, such as to calculate various numerical summaries of the data ? Something like the Collate field of the DESCRIPTION file of typical R packages, perhaps ? I suppose it is possible to have many source function calls at the beginning of server.R, but could there be a neater way ?

Huidong TIAN

unread,
Aug 31, 2015, 4:07:30 AM8/31/15
to Shiny - Web Framework for R
Yes, just put them all in your source file.

Dario Strbenac

unread,
Aug 31, 2015, 10:00:23 PM8/31/15
to Shiny - Web Framework for R
That should not be necessary, because it makes the application code harder to maintain. I was asking about having multiple smaller files, one for each function, which is good programming style. It seems that Shiny was designed with small applications that don't perform much processing in mind.

James Ferguson

unread,
Sep 1, 2015, 8:16:29 AM9/1/15
to Shiny - Web Framework for R
Try source (path,'local') it interprets the source as being inline where the statement executes

Dario Strbenac

unread,
Sep 1, 2015, 11:00:15 PM9/1/15
to Shiny - Web Framework for R
That's nice, because it doesn't add functions to the user's workspace, but I think that the R files shouldn't need to be explicitly sourced by the application developer.

Joe Cheng

unread,
Sep 1, 2015, 11:09:25 PM9/1/15
to Dario Strbenac, Shiny - Web Framework for R
I strongly disagree that one file per function is a desirable style, but to each his/her own, I suppose! A good IDE or text editor makes it very easy to jump between functions regardless of where they are (Ctrl-. In RStudio, Ctrl-P in Sublime Text).

How about having a folder in your app dir called e.g. "helpers" and then a single call in your server.R or whatever that sources everything in that directory?
On Tue, Sep 1, 2015 at 8:00 PM Dario Strbenac <dario....@gmail.com> wrote:
That's nice, because it doesn't add functions to the user's workspace, but I think that the R files shouldn't need to be explicitly sourced by the application developer.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/a5e7d56f-64e8-4fe2-aec5-316714116c00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages