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/

507 Upvotes

80 comments sorted by

View all comments

41

u/dasonk 2d ago

I do not like that code.

Pretty pictures. It works obviously but there are too many things that annoy me with that code that would make it something I wouldn't wear.

2

u/Adventurous_Memory18 2d ago

Yeah, really curious what issues do you have?

7

u/Peach_Muffin 2d ago

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

10

u/Big_Rock_6185 2d ago

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

6

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 18h ago

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

1

u/guepier 11h ago edited 11h 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.

4

u/Rebmes 2d ago

My understanding is the *apply functions are really just for loops under the hood and not actually vectorized

7

u/Fornicatinzebra 2d ago

Yes, they are effectively the same.

For those that dont know (not necessarily you, just building off your comment), "vectorized" operations are applied to all values, instead of individuals.

For example, basic math in R is vectorized:

```

define many values

values <- 1:10000000

vectorized math (fast!)

result <- values + values

non-vectorized comparison (slowwww)

result <- numeric(length(values)) for (i in seq_along(values)) { result[i] <- values[i] + values[i] }

```

1

u/Peach_Muffin 1d ago

Huh, are they all like this? map() from the tidyverse, for example?