http://www.perlmonks.org?node_id=1190455

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hey monks,

For my new job I'm having to learn R. I feel so sore about this and miss almost everything about Perl syntax and the unix command line. Anyone have any advice on how to make learning Rstudio a bit easier/ergonomic/ sensical if Perl+unix+bash is what you were raised on?

Was thinking maybe there are a few ways to approach R, whether that is having the right coding environment or learning style that will make this more fun!

Thanks for any input!
  • Comment on Hating learning R any advice for a perl guy?

Replies are listed 'Best First'.
Re: Hating learning R any advice for a perl guy?
by igelkott (Priest) on May 17, 2017 at 13:24 UTC
    having to learn R

    Had to do the same a couple years ago. Initially tried to minimize my expose to R with Statistics::R but was frustrated with the limitations on types of data structures which could be passed back and forth. Wrote my first R scripts in a C/Perl style with for loops, which resulted in painfully slow execution. In the end, I basically abandoned my Perl mindset and embraced vectors and implied loops. Simple Perl constructs can be so awkward in R that, in my opinion, it might be better not to think about Perl at all when learning R.

    Basically, R is an interactive tools which can be scripted ... but that's not really what it's made for. Data types can change unexpectedly (eg, a single-column matrix silently changes into a vector) and array indexing calls a function. The trick is to find the R way to do things since those call C-functions rather than pure R.

    I currently code in Perl, Python and R on a regular basis. I occasionally get mixed up but treating R like the completely unrelated language it is helped reduce the frustration.

Re: Hating learning R any advice for a perl guy?
by erix (Prior) on May 17, 2017 at 13:27 UTC
Re: Hating learning R any advice for a perl guy?
by swl (Parson) on May 17, 2017 at 21:50 UTC
      That is a great read for anyone here. :)

      (free PDF if not obvious)

Re: Hating learning R any advice for a perl guy?
by kevbot (Vicar) on May 18, 2017 at 06:22 UTC

    Lately, I seem to be using R about as much as Perl. I like both languages, but they are quite different. I have found that programming in R has influenced how I write Perl and vice versa.

    I think one of the biggest advantages of R is that spreadsheet-like data is supported with a native data structure, i.e. a data.frame.

    Certain modules make using Perl much more pleasant/efficient (e.g. Moose, Path::Tiny, etc.). The same goes for R. I find that I routinely use certain CRAN packages such as data.table, ggplot2, dplyr, reshape2, etc.

    When I encounter a task that involves spreadsheet-like data, I tend to go to R; however, there are times I want to stick with Perl. In these cases, I tend to use the Data::Table module (which is heavily influenced by R). I do sometimes wish that more R-like things would make their way back into Perl. For example, Python has a port of ggplot2, while I don't think Perl has such a thing.

    Also, there are some things that you can do in R to make things more perl-like. For example, most of the built-in regular-expression functions in R (such as gsub, grep, and grepl) take an argument perl = TRUE which will enable Perl-compatible regexps.

    I tend to dislike IDEs, so I don't always use Rstudio when programming in R. I'll often use vim and run scripts with Rscript. If you are a vim user, you may want to enable vim keybindings in Rstudio (in Preferences->Editing->Keybindings).

    So, my advice would be to find packages that you like. Perhaps you could find some problems and implement solutions in both R and Perl. That way you might start to see the strengths of both languages...and hopefully make working with R more pleasant.

Re: Hating learning R any advice for a perl guy?
by choroba (Cardinal) on May 17, 2017 at 12:30 UTC
    I've never used R, but noticed Statistics::R on CPAN.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: Hating learning R any advice for a perl guy?
by thanos1983 (Parson) on May 17, 2017 at 13:25 UTC

    Hello Anonymous Monk,

    To be honest I have never used R either but I also found (The R/Splus--Perl Interface).

    From the documentation:

    This package provides a bidirectional interface for calling R from Per +l and Perl from R. This embeds one interpreter (e.g. R) within the pr +ocess of the other interpreter (e.g. Perl). One can call routines and + functions in the other language as if they were part of the local en +vironment. This avoids having to program in a different language whil +e making the functionality in the other system transparently availabl +e with no additional coding. Values computed in one call are availabl +e to future calls. This makes Perl more interactive, also allows the +R/Splus programmer to use convenient and familiar syntax to mix compu +tations in the two different sytems, and provide statistical function +ality to Perl applications..

    Maybe a bit of more documentation could help on how to use it (How to use RSPerl).

    Hope this helps.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Re: Hating learning R any advice for a perl guy?
by stevieb (Canon) on May 17, 2017 at 23:15 UTC

    If it's a new job, learn R.

    You've signed up for something, so take responsibility for it. I appreciate your situation, but if you've agreed, man up.

    You can think this is belligerent, but I personally have had to change up many times in my career(s). I had to learn Python! (it's not that bad though).

    I like that other Monks are trying to help, but my advice is this: You have a new job that you've accepted, so learn the ropes of what they want. During this time, expose and explain your experiences elsewhere, and see what type of feedback you get. If you get none or the response is hasty or of a quality you don't like, quit and move along.

    As far as the right "coding environment" or "learning style", you won't get that until you actually bite into the new sphere, and get an understanding of it. I have worked in so many industries doing so many things, that it is impossible to accept new practices until one has some experiences.

    I say get a feel for the position, get an understanding if your employer is ok with you testing out new/different methods of production that may not be the norm, if you have them, flex some muscle, and if you can't flex, start looking for new opportunities.

    Jobs don't typically last 10-40 years like they used to... get in the game; the employment world is literally a roll of the dice anymore.

    ps. it doesn't hurt to learn new things, in this case a new language (if it is a language, I don't know). Take what you can...

Re: Hating learning R any advice for a perl guy?
by sundialsvc4 (Abbot) on May 17, 2017 at 16:18 UTC

    I suggest that you approach each of these as fundamentally different languages, intended for fundamentally different purposes.   R is a programming language that is not “general-purpose.”   It is very-specifically designed for statistics.   Unlike tools such as SAS® and SPSS®, which are based on monolithic modules (each dripping with options) that are tied together – if at all – by relatively primitive scripting facilities, R offers the statistician a true programming-language environment that is targeted for his tasks and mind-set.   (It is no wonder why SAS, SPSS, and everybody else promptly created interfaces to it, and openly encourage its use.)

    A useful analogy to the present situation is when you embed R programming into a project that was built using a conventional tool like SAS or SPSS:   the two tools work together, but, within its element, R is running the show and the stats-package is supporting it.   The same will undoubtedly be true for the hybrid applications that you write where Perl is the tool supporting it.   Don’t try to do Perl things the R way, nor R things the Perl way.   Study R examples to see, not only how this language “works,” but also how it “thinks.”   Spend a few days in which you do not fire-up the Perl interpreter at all.   As you found with Perl, soon you will be saying (about some particular aspect of R), “gee, that’s kinda cool!”   (And so it is.   You will not “hate learning R” for very long ...)

    As you write your tools, also consider your audience.   There is a large “impedance mismatch” between the Perl and the R mind-sets, and researchers are likely to be more-familiar with R.   Try to avoid requiring them to confront this mismatch and to switch back-and-forth between the two environments in their design of a solution, even if they are familiar with both.   A pure-R implementation of a particular section is probably more-favorable than a mixed one, and concerns such as “execution time” or “efficiency” usually are considered to be secondary, within reason, unless they say otherwise.   Consult the R-gurus within the organization frequently as you design your tools.

      "I suggest..."

      Please don't.

      «The Crux of the Biscuit is the Apostrophe»

      Furthermore I consider that Donald Trump must be impeached as soon as possible

      "As you write your tools, also consider your audience."

      Right back at ya on that one. Do you?