Alphaneo Alphaneo - 11 days ago 7
R Question

Global variables in R

I am a newbie in R programming. Though I am poking into the manuals, I also wanted to ask the community "How can we set global variables inside a function?"

Any pointers will help.

Question-2: Regarding plotting,

I am using plotting multiple graphs in a single sheet, and to differentiate each one of them, I want to add title for each one of them. Can anyone tell me how I can achieve this?

Answer

Use one post per main question.

  1. As the first answer with assign() showed you, there is a way to assign in the global environment. A simpler, shorter (but not better ... stick with assign) way is to use the <<- operator, ie

    a <<- "new" 
    

    inside the function.

  2. For your plots, use main="My title here" for each plot. Use something like par(mar=c(3,3,3,1)) to give sufficient spacing.