Skip to main content
Search form
  • 00:01

    MATT DENNY: Hi, everyone.This is your instructor, Matt Denny,and welcome to this lecture on getting help with your Rprograms.So I often find that learning how to effectively lookfor help, learning how to get help,figuring out some bug in your code or how some function worksor just how to do something in R,

  • 00:22

    MATT DENNY [continued]: is often more important, or at least asimportant as just having a lot of experience with coding.So on a daily basis, I am looking for help.I'm scouring the internet for help on all sorts of things,whether it's some brand-new thing that I'mtrying to figure out how to do or just rememberinghow to use some command I've used 1,000 times,but I always forget how exactly I have to use it

  • 00:47

    MATT DENNY [continued]: or what exactly it outputs.So there are two ways to get help with R, broadly.R has really, really nice built-in help libraries,so built-in documentation that comeswith a lot of the functionality that R provides.And you can access that using the help function.So that's something we're going to go over.Also, the internet is really your friend.

  • 01:09

    MATT DENNY [continued]: So many people have spent so much of their livesputting so much information on the internetto help people with R code.It's mind-boggling.It's wonderful.I'm guilty of sinking hours and hours into providing peoplewith help, both using some of the R code that I've written,but also just learning how to do stuff.

  • 01:29

    MATT DENNY [continued]: And in fact, I'm here.I'm providing you with these lecture materials,but a lot of these materials startedas me posting tutorials or help-related stuffon the internet.So with that, we're going to head over to the desktop,and we're going to start in R, and thenwe're going to end on Google.

  • 01:50

    MATT DENNY [continued]: So let's head on over now.OK, so I'm on my desktop.Again, I'm going to finish up the basic R programming scriptthat we've been working with.So we're just going to go over the last couple lines of that.So the first thing we want to go overis using the help function.

  • 02:11

    MATT DENNY [continued]: So the way the help function works--again, it's a function, so you type out the name help,and then in parentheses, you put the argument to the function.And in this case, the argument isgoing to be another function.And the one that we're going to start withis something called the print function.We've already gone over cat versus print

  • 02:33

    MATT DENNY [continued]: in our previous lecture.And so if we want to learn a little bit moreabout the print function, we can dothat using the help function.So let's run this line of code.And what we see is that over in our Help pane in RStudio,we're going to get something that pops up that tells usabout the print function.It's going to tell us that it's used to print values.It's going to give us a description, usage,

  • 02:55

    MATT DENNY [continued]: which will also tell us about some of the other argumentswe can give this function.So we can give print, for example, a quote argumentand other things like this.These are things we're going to get into later.But it'll give you some basic idea of the usage.It'll also describe, in the Arguments sectionof the documentation, what each of the arguments

  • 03:19

    MATT DENNY [continued]: to this function does.In other words, you can flip little switches.You can change settings in the print functionto change how it prints stuff out.But perhaps the most useful thing in a help fileis if we scroll all the way down to the bottom,we can get to example code.So it'll actually give you working example codefor how to use that function, which

  • 03:41

    MATT DENNY [continued]: can be so, so helpful when you're starting out.Maybe I didn't know how the print function worked,or maybe I wanted to learn about some other function,like a regression function or a plotting function.This should actually give you working codethat you can try out.One important thing to note is thatin the References section--so this is particularly true for statistical models or network

  • 04:04

    MATT DENNY [continued]: models or any of these machine learning-related stuff that youmight run into--oftentimes, it'll give you a referenceto a paper that talked about that method or that model.And that can be really, really helpfulto understanding what's going on with it.So anyhow, these help files are super, super useful.We can use them not only to look at simple things like the printfunction.

  • 04:24

    MATT DENNY [continued]: So one other function that we're going to be using down belowis the sum function.So the sum function will take as input some object,and it will return the sum of all the elementsin that object.So if it's a vector, like my_vector,then it's going to return the sum of all the numeric elementsin that vector.

  • 04:46

    MATT DENNY [continued]: Now, there's one other way besides the help function,a shorthand way of using that.And that's to put a question markbefore the name of a function.So the length function is another interesting functionthat we're going to use right below.And let's learn about it.So to do that, we'll use the question markimmediately followed by length.And that will also bring up the help file

  • 05:06

    MATT DENNY [continued]: for the length function.So the length function--essentially, it takes some objectand it tells us the number of slots in it.So this is particularly relevant with a vector.So let's try it out.So I'm going to create this variable.I'm going to call it my_vector, and it'sgoing to concatenate together the numbers 1, 2, 3, 4, and 5.So let's run this line of code here.

  • 05:27

    MATT DENNY [continued]: Let's go over to our environment.And what we'll see is that in our environment,we now have this my_vector, and it'sa numeric vector of length 5, and it containsthe numbers 1, 2, 3, 4, and 5.So the first thing we might want to dois say, how many slots are in this vector?Well, we learned about the length function.So let's try that out.OK, so we can learn here that the length of my vector

  • 05:48

    MATT DENNY [continued]: is of length 5.It has five boxes.It has five slots in it.We can also take the sum of this vector.And so let's try that here too.And OK, we see that it sums to 15.And that makes sense.1 plus 2 plus 3 plus 4 plus 5, if you do out the math,it in fact sums to 15.OK, so right now, what we've been doing is

  • 06:09

    MATT DENNY [continued]: we've been looking at help files for relatively simplefunctions, where we might be able to just tellwhat the function does by reading its name.But let's check out the log function.So earlier in the very beginning of this topic,we talked about some math operators.And one of them was the log operator.And if you remember, the log operatoris by default in base e.

  • 06:30

    MATT DENNY [continued]: In other words, it's the natural log.So let's look for help with the log function.And what we can notice here-- so thiscomputes the natural logarithm.But down here, in the Usage section,we can see that there are other different waysto take logarithms.So there's logb, which will let youset the base for a logarithm.

  • 06:51

    MATT DENNY [continued]: You can also do things like the log base 10 or the log base 2.These are both really useful dependingon what your application is.So we can learn about these related functionsoftentimes, by looking at the Usage section in the help file.And so we can take the log base 2 of 64, which is 6.

  • 07:12

    MATT DENNY [continued]: In other words, if you take 2 and raise it to the power 6,you'll get 64.So that's 2 times 2 times 2 times 2 times 2 times 2.We could also take the log base 10 of 1,000.And that would be 3.So 10 to the third is 1,000.So these help files are really, really useful.

  • 07:32

    MATT DENNY [continued]: They pop right up inside of RStudio.But what happens if you need morehelp than RStudio can give you?So I'm going to talk to you about just a coupleof options that I commonly use.OK, so let's minimize our RStudio session,and let's pull up Google.OK, so one of the classic places to look

  • 07:54

    MATT DENNY [continued]: for help with our programming or any kind of programmingis StackOverflow or StackExchange.So if we type in "R StackOverflow," into Google--let's do that--and what do we see?

  • 08:14

    MATT DENNY [continued]: We can see-- it should be near the top,and we'll link this as well--the All R Language Topics on StackOverflow.So StackOverflow is this community websitewhere people go, and with no compensation,they post a whole bunch of useful stuff about howto do all sorts of things in R and a ton of other programminglanguages.

  • 08:35

    MATT DENNY [continued]: So we can see, there's even a GettingStarted With the R Language topic.So for example, if we click on this,it'll talk us through their own guideto installing R on a lot of different operating systems,getting help, interactive mode, and R scripts.There's all sorts of stuff in herethat can be very interesting.

  • 08:56

    MATT DENNY [continued]: There are things about installing packages.That's add-on materials that we'll get to.Reading and writing strings.There's just all sorts of things that might end upbeing useful for us.So these topics are often very handy.Another thing that I would suggestyou start learning how to do--this is the standard way that I do things, is, say

  • 09:21

    MATT DENNY [continued]: I wanted to make a scatterplot.I wanted to plot two variables.So the classic way that I start a query in Google about thisis, I say, "R how do I," and then "make a scatterplot."OK, let's try that.

  • 09:42

    MATT DENNY [continued]: And what do we see?Usually, something useful will pop up towards the top.So Quick R is one of my favorite curated websites for R help.There's actually a book called R in Action,but it's associated with this website.

  • 10:03

    MATT DENNY [continued]: And it has really nice, clean example codefor doing a whole lot of stuff.So you can make crazy-looking scatterplots,and you can learn about how to do this with R from is a weird name for Quick R.You would have thought the guy who wrote this bookand created this website would have called it Quick R,

  • 10:24

    MATT DENNY [continued]: but it's called, this is one of the handy places to look for.Also, oftentimes you'll see shorter tutorialsthat people wrote.What a nice-looking scatterplot.So R Bloggers is a really nice website.And these people, again, just post

  • 10:45

    MATT DENNY [continued]: a whole bunch of their code and example code,talking through how to make pretty scatterplots.So my advice to you is, you should use the built-in helpfunction in R. If that doesn't work,you can always try StackOverflow,but also, just typing in "R how do I,"and then the thing that you want to do.

  • 11:06

    MATT DENNY [continued]: It will usually bring you to some helpful Google resultswith example code that you can actuallyuse to do whatever it is you need to do.So don't feel shy about searching for help in R.Like I said, I probably spend more time looking for R helpthan I spend actually writing R code these days.It's definitely something to check out.

  • 11:26

    MATT DENNY [continued]: And I hope you found this helpful.So that should conclude our real basic introductionto R programming.And we're just going to move forward from here.So thank you very much for watching this lecture,and I will see you in the next one.

Video Info

Series Name: Practical Data Management with R

Episode: 13

Publisher: SAGE Publications Ltd

Publication Year: 2017

Video Type:Tutorial

Methods: Data management, RStudio, R statistical package, Programming

Keywords: coding; computer programming; data structures; open source networks; open source software; programming and scripting languages ... Show More

Segment Info

Segment Num.: 1

Persons Discussed:

Events Discussed:



Matt Denny explains various ways to access help when working with R functions, from within RStudio and from internet sources such as Stack Exchange, Quick-R, and R-Bloggers.

Looks like you do not have access to this content.

Introduction to RStudio: Getting Help with Your R Functions

Matt Denny explains various ways to access help when working with R functions, from within RStudio and from internet sources such as Stack Exchange, Quick-R, and R-Bloggers.

Copy and paste the following HTML into your website