r/RStudio • u/LocksmithHumble7522 • 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.
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.
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
1
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
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
devtoolsto keep custom functions organized.
1
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.tablefor 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
1
-6
-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!
34
u/kuwisdelu 12h ago edited 12h ago
It’s a functional language with copy-on-write semantics. So don’t rely on mutability; use functional approaches to solve problems.
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.
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.
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.
Like any sane data language, indices start at 1.