njtierney,
@njtierney@aus.social avatar

New post: "How to get good with R", where I ramble on some ideas on getting better with R - keen to hear what people think I've missed and discuss the topic!

https://www.njtierney.com/post/2023/11/10/how-to-get-good-with-r/

#rstats

jroper,
@jroper@transportation.social avatar

@njtierney "If you’ve found yourself copying the internals of a function over to another script and hard coding the arguments at the top of the script and running the code line by line, then this is especially for you."

I feel like I do this more in Python than in R, any tips for that?

njtierney,
@njtierney@aus.social avatar

@jroper Alas I'm not much of a python programmer - but I think you are after the pdb Python debugger - this might help: https://stackoverflow.com/questions/44727981/rs-browser-equivalent-in-python

milesmcbain,
@milesmcbain@fosstodon.org avatar

@njtierney 👍👍👍

One little twist on browser() that comes in handy for me is putting it behind an if() that represents the conditions in the error, if they’re interpretable. If the error is about thing being NULL, but thing is an element of a list inside an iteration you can do:

If(is.null(thing)) browser()

To get right to the error situation. Works better than recover in some cases.

eliocamp,
@eliocamp@mastodon.social avatar

@milesmcbain @njtierney You can do browser(expr = is.null(thing)!

njtierney,
@njtierney@aus.social avatar

@milesmcbain Oh that's neat, I like that!

njtierney,
@njtierney@aus.social avatar

@milesmcbain ended up using this pattern to sort out an error today!

PhilipLeftwich,

@njtierney I'm going to go with something simple but effective. Start using projects and ditch .RData files.
It's a quick step towards making people think about their scripts as where the work gets done and having a clean, complete workflow.

njtierney,
@njtierney@aus.social avatar

@PhilipLeftwich Totally agree! It's one of the first things I tell people in a course or I'm helping them with something - first lets make sure we have the project and untick those boxes that save .RData files. I think I'm going to need to write another post.

gavin,
@gavin@fosstodon.org avatar

@njtierney This is a great post. It arrived at the perfect time for me, too.

Yesterday, after reading your post, I was inspired to use browser() for the first time. I am honestly not sure why I hadn't used it before... :blobcatgooglyshrug: It was great to use and helped me create several useful abstractions in some custom functions.

I feel I have improved significantly by:

  1. Writing functions
  2. Reading other people's source code
  3. Refactoring my functions with what I have learned.
njtierney,
@njtierney@aus.social avatar

@gavin Thanks for the kind words, I'm so stoked that it arrived at a good time for you - browser() is awesome! I also really enjoyed @milesmcbain 's "stop() - breath - recover()" video: https://www.youtube.com/watch?v=M5n_2jmdJ_8&t=1s

Totally agree with your 3 points - thanks for sharing! :)

isabellaghement,

@njtierney Really nice post, Nick!

For me, what really helped was learning via Twitter how to use nest_by() to iterate over rows of list-columns. Nesting is such a nifty concept and I find myself using it more often than for loops these days. I still struggle with its subtleties but for the most part I can pull it off.

njtierney,
@njtierney@aus.social avatar

@isabellaghement thanks! I think nesting and that world of map and purrr and iteration helped me really understand functions in a deeper way. I should link to @hadleywickham ’s functional programming video introducing purrr and friends with the awesome EDA of gapminder

rob_models,
@rob_models@mas.to avatar

@njtierney thanks Nick! I'm working on my first real R project, so the language-specific stuff is particularly helpful 😃

njtierney,
@njtierney@aus.social avatar

@rob_models thanks!

mccarthymg,
@mccarthymg@fosstodon.org avatar

@njtierney Nice post! I think what helped me the most in getting good with R (in addition to a lot of your suggestions) was using it regularly through a mixture of necessary projects, hobby projects, and self-study.

Choosing a diverse range of projects really helped too (e.g., web scraping, package building, blogging, data analysis, etc.), since I always ended up learning at least one new thing that I could apply in (unrelated) future projects.

njtierney,
@njtierney@aus.social avatar

@mccarthymg completely agree that having a project to use R for is a strong focus and motivator! Good points re diverse projects as well, as you use it for different things you learn new skills and also see new ways of using functions. Great point!

mccarthymg,
@mccarthymg@fosstodon.org avatar

@njtierney One other thing I value about learning and practicing on my own time is that there’s no pressure of a deadline or deliverable. I find it’s easy to fall into bad practices when that pressure is there—even when I know better—because it can be easier in the moment.

So for workflows I care about that could have been done better, I find it helpful to revisit them on my own time, where I have the space to refine my approach. Then I have something better to reference next time!

ellakaye,
@ellakaye@fosstodon.org avatar

@mccarthymg @njtierney I do this too, but to such an extent that, because there always seems to be another improvement I can make, I never actually get round to sharing the project (even when that’s the intention). I find that a deadline, even if self-imposed, can be helpful.

ellakaye,
@ellakaye@fosstodon.org avatar

@mccarthymg @njtierney At the moment I’m working on a project related to that it would make a lot of sense to share before December 1st. Plus, now that I've said here that that's what I'm doing, that'll serve as extra motivation for me to actually get it done and publicised by then!

njtierney,
@njtierney@aus.social avatar

@ellakaye @mccarthymg It is nice to have projects on your own time so you can get them done to the standard that you want, but then I find sometimes I just need to get projects out the door or they will never get done - my blog post could have had some better more polished examples, and I think especially talking to some folks here and other places I might make some edits for clarity.

But I find it is better to get something written and out there and shared, than to hold onto it until it is totally done. Working in public, or sharing things publicly I think helps you stay honest and importantly, get stuff out there!

Excited to see what your project is, @ellakaye !

maelle,
@maelle@mastodon.social avatar
ellakaye,
@ellakaye@fosstodon.org avatar

@maelle @njtierney @mccarthymg Agreed! I remember a version of this talk well from useR::2017. All my work is technically public, in that I develop ‘in the open’ on GitHub, but I feel unless I make an effort to actually tell people about it, then it will hardly be seen. I always like the idea of doing some kind of big launch, and usually want to wait until a project is complete to do that. But I know I should be less perfectionist about that.

njtierney,
@njtierney@aus.social avatar

@ellakaye @maelle @mccarthymg That's the talk, thanks, Maëlle!

Sometimes perfect is the enemy of good. But there's a sweet spot in there somewhere.

Greg_Dubrow,

@njtierney Yes to descriptive & consistent naming. In grad school (using SAS) I was working w/ large datasets, creating tons of variables. Learned early on to make sense of it all I needed labels to tell me what they were & be easily sortable A-Z.

Functions...for some reason my bugaboo in r. Oddly, learning Python recently the shroud of confusion was listed & I think I get it how to write a useful basic one now. Though need to work on more complex functions.

Also? Writing a personal package

njtierney,
@njtierney@aus.social avatar

@Greg_Dubrow totally agree re writing a personal package - it is a bit of a jump, but for me that’s where I think I really started to understand writing functions in a deeper way. A set of tools that all work together for a general task, you know?

jospueyo,
@jospueyo@fosstodon.org avatar

@njtierney For me, the most useful way is reading the websites of packages and engaging in discussions here under the hashtag.

njtierney,
@njtierney@aus.social avatar

@jospueyo totally! It’s a great way to see what people are doing, and how they solve problems.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • Durango
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • osvaldo12
  • khanakhh
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • everett
  • ngwrru68w68
  • kavyap
  • InstantRegret
  • JUstTest
  • GTA5RPClips
  • cubers
  • ethstaker
  • normalnudes
  • tacticalgear
  • cisconetworking
  • tester
  • Leos
  • modclub
  • megavids
  • provamag3
  • anitta
  • lostlight
  • All magazines