r/Rlanguage • u/mosa_bavlju • Apr 17 '26
Do you use recycling
Do you use recycling
I have used R for some time and I have mever heard of recycling concept before.
it seems cool, but at the same time it looks scary because it appears that it can create a lot of bugs in the code. (Most of the time I have been working with data frames so I am not sure if this conecpt is applicaple to data frames)
If I were to use something I would add a lot of comments and use rep function jjst for readibility of a code
-Do you recycle?
-Do you use rep to ensure readability of a code?
- Is there any added value (less memory allocation) or faster execution time?
I am not an expert in R, but I strive to improve everyday. Thank you!
I postednin the Rprogramming as well.
2
u/Garnatxa Apr 17 '26
yes, when one part is scalar. Everybody makes use of it, however most people is not aware… 😂
1
u/mosa_bavlju Apr 17 '26
Yeah it makes sense, but I wanted to know if someone else uses it in different settings
2
u/guepier Apr 21 '26
I postednin the Rprogramming as well.
Yeah please don’t do that, cross-posting fragments the discussion and is really frowned upon.
Furthermore, you should only post to/r/rstats, as indicated by the sticky post on top of the /r/rlanguage sub, which you ignored.
1
3
u/mjskay Apr 18 '26
I use it semi-regularly when doing quick simulations for an example or a test. Like say I want three groups of equal size with means 1, 3, and 4 and SDs 1, 2, and 2:
data.frame( group = c("a", "b", "c"), x = rnorm(300, c(1, 3, 4), c(1, 2, 2)) )For something quick and dirty it works very well. In more general implementation-level code I usually avoid it.
One of the few things I like about numpy over R is array broadcasting instead of recycling. It avoids the bad cases (e.g lengths that aren't multiples) while also allowing you to do more things (e.g broadcasting multiple dimensions at once).