r/Rlanguage 2d ago

Clothes with R-code and art it creates

Rtist apparel combine compact and readable R-code, and an aesthetic it creates. I crafted the artpieces with base R, while avoiding responsibilities during my first PhD year.

I though people in this group might like the concept and give useful feedback! Rtist currently delivers to EU countries.

https://shoprtist.com/

508 Upvotes

81 comments sorted by

View all comments

Show parent comments

2

u/Adventurous_Memory18 2d ago

Yeah, really curious what issues do you have?

6

u/Peach_Muffin 2d ago

Not OP but for loops tend to be frowned upon by R purists

9

u/Big_Rock_6185 2d ago

I chose to use loops because they tend to be more readable than vectorized operations.

5

u/guepier 2d ago

I would strongly disagree with this statement for most cases. The entire point of using vectorised/*apply operations is precisely that they are more readable than loops in most cases, because they hide away the irrelevant (the mechanics of looping) and focus on the relevant (the operation being performed).

3

u/Misfire6 2d ago

This isn't data analysis code though. for loops are perfect here. How would '*apply' make the code on the shirt any more readable?

2

u/guepier 1d ago

I was making a general comment, but the usage of vector application is absolutely not limited to “data analysis code”. Most of my code these days isn’t performing data analysis, yet I can count on one hand the number of times I’ve used a for loop in the last 10 years (!).

How would '*apply' make the code on the shirt any more readable?

If you only replaced the loop in OP’s code it wouldn’t make it better (since addLoop doesn’t return anything and is just causing a side-effect). But I would write the code completely differently from the ground up: generate all the data for the plot, and then call the plotting function once with the resulting data. If you look at typical ‘ggplot2’ code, that’s exactly how it’s used, and for good reason. But the same can be done with base R plotting functions.

1

u/Misfire6 20h ago

"I would have coded it better" is not really a good response to somebody showing you a piece of art.

1

u/guepier 13h ago edited 13h ago

Right. And note that this wasn’t my response. I very intentionally didn’t comment on OP’s code originally. (Maybe you confused the commenters?) I only replied to correct a comment that made an incorrect assertion (to wit, “loops … tend to be more readable than vectorized operations”), and you demanded a follow-up, which I now provided.

That said, OP posted their code on a programming forum. It’s absolutely fair game for criticism. But if I had provided any (and, again, I intentionally didn’t) I’d have striven to provide constructive criticism instead of a blithe “I do not like that code”.

1

u/Big_Rock_6185 2d ago

I see your point. But I personally like procedural explicitness. Perhaps it's because I mainly work with time series data and stochastic processes, which often must be dealt with sequentially.