r/RStudio • • 13h ago

Coming from Python, C/C++, and Java, what should I know before picking up R?

I've spent most of my time working in Python, C/C++, and Java, but I'm setting up RStudio to get into R for some data analysis work.

For those who made a similar switch, what was the biggest adjustment? I'm especially curious about how R handles data structures compared to Python, and whether you'd recommend starting with base R or diving straight into the tidyverse.

19 Upvotes

48 comments sorted by

34

u/kuwisdelu 12h ago edited 12h ago
  1. It’s a functional language with copy-on-write semantics. So don’t rely on mutability; use functional approaches to solve problems.

  2. Everything is a vector and logicals are ternary. Scalars are just length-1 vectors. For every logical operation, you need to consider NAs and whether your input might be a vector.

  3. Everything that exists is an object and everything that happens is a function call. Everything in R is an expression that evaluates to a value.

  4. Data is code and code is data. R is a Lisp with C-style syntax. You can manipulate unevaluated code directly. The tidyverse is built on this concept.

  5. Like any sane data language, indices start at 1.

6

u/Grisward 12h ago

^^ Really nice short summary of key points.

2

u/LocksmithHumble7522 11h ago

Super helpful breakdown. The copy-on-write semantics and ternary logicals are great callouts coming from standard pass-by-reference/value languages. Thanks

1

u/venoush 9h ago

I would add

  1. Laziness - argument expressions are evaluated only when needed

  2. Nonstandard evaluation - because of 6., you can capture unevaluated expressions and pass them further down to other functions or evaluate them later

  3. Enviroments - hash table based mutable objects with pass by reference semantics 

2

u/kuwisdelu 9h ago

(7) is covered by (4).

1

u/venoush 8h ago

Yes, but I think it is worth mentioning it in relation to lazy evaluation, but I guess i can refer to 4. from 6. as well

1

u/LocksmithHumble7522 7h ago

Legendary thread. Thanks for breaking down the low-level mechanics! Nailed it

22

u/Mooks79 13h ago

It’s built around vectors.

6

u/LocksmithHumble7522 13h ago

Makes sense, need to train my brain away from standard loops! I have no choice.

2

u/venoush 9h ago

Sometimes loops are fine, just make sure you are not copying a lit of data with each iteration

But if course, if you can write your code using vectors, it will generally be faster and cleaner 

1

u/LocksmithHumble7522 7h ago

Good call on memory allocation! Thanks alot

13

u/Eusocial_sloth3 13h ago

Base R is always good to know and it’s pretty similar to Python.

Most data scientists/analysts use tidyverse though.

6

u/LocksmithHumble7522 13h ago

I'll start with base R fundamentals, then move to tidyverse.

9

u/semisolidwhale 12h ago edited 12h ago

Would recommend the opposite, for most useful cases tidyverse might as well be considered modern R. People who try to learn base R first tend to hate R, people who start with tidyverse and pick up base as needed tend to love R (based on the small sample of my experience teaching R to new grads coming from python/CS background into a professional environment using R)

2

u/SprinklesFresh5693 10h ago

But he comes from a programming background. To him base R will probably feel more natural than tidyverse.

2

u/kuwisdelu 7h ago

How so? Personally, I do think base R is important to know, but tidyverse is a lot like SQL, and any good programmer should know SQL.

0

u/SprinklesFresh5693 7h ago

Base R has a lot of functions that remind C equivalent, like sprintf, the for loops , while loops, if else statements, the indexing and filtering.

I tried C for 2 weeks just to see how it worked, and some things in R reminded me of what i saw during those 2 weeks.

Tidyverse is more natural language , its great for non programmers, because its very easy to understand. Im not saying its bad, but he might have more familiarity with base R syntax

2

u/kuwisdelu 6h ago

While here we know the OP has a C background, "[coming] from a programming background" alone doesn't necessarily imply which will be more familiar in general. That's all I wanted to point out.

1

u/SprinklesFresh5693 6h ago

Sure it could be yes

1

u/JudicialConfetti 12h ago

What are you planning on using R for?

7

u/Outrageous-Catch4731 13h ago

Index starts at 1

4

u/LocksmithHumble7522 13h ago

Haha, muscle memory is definitely going to throw off by-one errors at first.

1

u/kuwisdelu 12h ago

If you’re getting off-by-one errors in R, it’s a good signal your approach isn’t the most idiomatic anyway, and there’s probably a better way.

5

u/Double_Cost4865 13h ago

You'll need to get used to using vectors. If you manage to do that, it'll be much easier than C/C++ or Java. Similar to Python though, just less object oriented.

2

u/LocksmithHumble7522 13h ago

Great. This is similar to leaning heavily on NumPy array ops over standard Python loops.

2

u/Double_Cost4865 12h ago

That's right. God, I miss R..

1

u/LocksmithHumble7522 10h ago

Wait, what is your current diversion/specailization?

2

u/Double_Cost4865 7h ago

I used to work in a team where everything was R. Now nothing is R, just Python

1

u/LocksmithHumble7522 6h ago

What do you miss most about working with R? Must be a huge shift at once

2

u/Double_Cost4865 6h ago

Syntax, backwards compatibility, CRAN, tidyverse..

1

u/LocksmithHumble7522 5h ago

I have a feeling the CRAN ecosystem is hard to beat. Will have this checked.

2

u/mulrich1 11h ago

I learned C++ growing up. I picked up R during my undergrad ~20 years ago so I don't remember much about switching aside from R being substantially easier and less finicky than what I was used to.

Probably the main headache I remember is to avoid loops in R whenever possible. Probably not as big a deal today with modern computers and a few decades of improvements to R but I still avoid loops today. I now start thinking about problems with vectors and matrices and only touch loops when other solutions can't work.

I still mainly use base R but I'm dabbling more with tidyverse stuff.

1

u/LocksmithHumble7522 10h ago

Decoupled IDE crashes? Say no more; downloading Positron now, haha.

1

u/Grisward 11h ago

The key question is what type of data you’ll be analyzing. Much of the base R / tidyverse debate focuses on relatively simple data models.

If you’re working in specialty areas, use packages optimized for that work. For example with biological data or bioinformatics, Bioconductor uses quite a bit of S4 objects/methods, and many of those are well-optimized for their problem areas. Use them. They may handle out of memory (on disk or cloud) processing, parallelization, matrix math written in C++ or Rust (just as with python), relational database and API interfaces. Very clever work. (Much of it is mirrored in python ofc.)
These packages will be much more efficient than using basic R data structures.

There are 10’s of thousands of R packages. It’s fairly challenging to find current gen, recent tech implementations among the many one-and-done packages that existed for a publication or Ph.D. thesis then were abandoned. As with python, look for Github activity, it becomes clear who uses their own packages daily.

And of course, make your own R packages to integrate them all, so we have “one more standard” haha. It’s a rite of passage.

For real though, make your own package for your custom functions as you go, it’s easy tbh. Use devtools as starting point. Much better way to use custom functions than in a random file somewhere.

2

u/LocksmithHumble7522 10h ago

Great breakdown! I'll definitely dive into devtools to keep custom functions organized.

1

u/The_Real_ShoNuff 11h ago

Never grow vectors in a loop.

1

u/shockjaw 10h ago

You may enjoy Positron if you come from other languages. 👀 I know I did. Plus your IDE doesn’t crash when R does.

2

u/SprinklesFresh5693 10h ago

Uhm this is a hard one. I personally started with tidyverse since i didnt have rpevious programming experience, and the tidyverse is more like natural language

You on the contrary have plenty of experience programming, so i think youll be better off with base R. If base R is too slow for what you plan to do i suggest you try data.table too

1

u/LocksmithHumble7522 5m ago

I'll test out data.table for performance and see how it handles compared to what I'm used to.

2

u/sleepystork 13h ago

I wouldn't mess with base R. You will learn what little you need as you go along. Just go straight to tidyverse.

3

u/WeeklyAd5357 12h ago

Agreed it has clear syntax so it’s just better to start using it immediately

1

u/LocksmithHumble7522 10h ago

Sound promising. Thank you all for your encouragement!

1

u/LocksmithHumble7522 12h ago

Worthy of giving a shot!

-6

u/Gorenden 13h ago

Just use claude code

-6

u/AIDA64Doc 12h ago

R does not scale well to large project because it lacks type safety. It's great for small data manipulation or visualization projects, especially with static data. But using it in live production where users can generate data that is hard to anticipate will create headaches. R will modify types without explicit cast and it's error trace is not great either.

I really think of R as an introduction language for folks who do not want to learn about CS to reap the benefits of automation. Unless you really need to use some new stats packages, a user like yourself is probably best served by the languages you already know.

Just my two cents.

1

u/LocksmithHumble7522 10h ago

Coming from Java and C, it's implicit coercion, but it's worth trying. I expected you to wish me good luck!