This is not specific to set_edge_attr but a fundamental principle of R. Like typical functional languages, R uses call-by-value, and functions cannot modify their arguments. All other functions will return modified values as well, instead of modifying variables passed to them.
First, I have to say that I rarely use R and can’t really say what is / isn’t considered good practice … My involvement with igraph is mainly through its C core and Mathematica interface.
However, I would not say that g$main <- "This is bad practice". I don’t think there’s anything wrong with that.
My point was that it is not possible to write an R function that changes a variable. The following is not possible:
x <- 1
f(x)
# now the value of x is 2
Only this is possible:
f <- function(a) { a + 1 }
x <- 1
x <- f(x)
This is because conceptually, R works with values, not with references. Some other languages, like Python, work with references, and you can do this:
In [1]: a=[1,2,3]
In [2]: b=a
In [3]: b[1]=100
In [4]: a
Out[4]: [1, 100, 3]
Notice that modifying b modified a as well. More accurately, a and b refer to the same data structure. In R each variable name is associated with an independent value. Modifying one variable will never affect another. Thus modifying a (local) function argument won’t change the (global) variable that was passed to the function.
All that said, generally speaking, improvements to the documentation are very welcome. Feel free to open pull requests with doc improvements. The R/igraph docs certainly need an update.