0

Is there any way in R to write a macro like one would in SAS? That is, I want to write a macro with some input variable (corresponding to a row in a dataset) so I can quickly make a plot of certain characteristics from said row. Any information regarding a package/method to do so would be greatly appreciated.

michael_p
  • 3
  • 2
  • 1
    R doesn't use macros. In R, we write functions to perform common tasks easily. But this question is far too broad to answer specifically. This type of thing would generally be covered in any R tutorial about writing your own function. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) of a specific problem with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Dec 06 '19 at 19:03
  • @mrflick thanks for letting me know, i appreciate the feedback! – michael_p Dec 06 '19 at 19:06
  • As mrflick noted, the R equivalent of a macro is a function. A couple of intros to writing functions that I have found helpful are included in [R for Data Science](https://r4ds.had.co.nz/functions.html) and [Hands-On Programming with R](https://rstudio-education.github.io/hopr/basics.html#write-functions) – natej Dec 06 '19 at 19:46

1 Answers1

0

R will generate some very, very, very basic code for you. If you have RStudio installed, you can click File > Import Dataset > From ... point to your file and click 'Open'. R will automatically create the code to do the import. Again, this is very basic. You really need to know how to code to do anything useful.

You get out of it what you put into it, so spend some time learning this stuff, and inevitably you'll learn a ton. I've found that it's very helpful to read through people's questions that are posted here, and try to solve the problem yourself. You'll learn a lot that way and you'll see what the current trends are. Reading books is great, of course, but sometimes I feel like some authors are too academic, and in the real world, sometimes it's done differently than what you see in textbooks.

ASH
  • 20,759
  • 19
  • 87
  • 200