Data Science Initiative Introduction To R Bootcamp (part 2)

So we list these at the top it helps it’s I list it at the top not when we use them it makes more sense to load them when you use them but then I can’t see them so it’s.

Easier to do it this way what you can do is this library of ggplot2 if you want ok now there’s an issue here some which is this will fail if ggplot is not installed okay now if you’re gonna be really nice to okay if you’re okay.

If you’re if you’re gonna be nice okay that’s great this just says it’s an error and I look at it and go.

Okay I see what the problem is I do I want to install ggplot2 alternatively so we I do see people.

Write this okay which is ggplot2 okay these are almost synonyms but they’re not this one says this says go load ggplot2.

And by the way if you fail just keep going which is.

Really bad news because I’m gonna fail way down deep in the in the script so.

This this is bad okay so this is.

Bad don’t don’t use this but okay what you can do if you want if you really want well sure you can say if that’s false if that fails then why don’t you just go and install eg plot – okay and that’s a handy little thing to.

Actually do because that says okay this this.

This this script will rescue itself okay this script will actually ensure that the right things happen okay and this is an if statement that says check this condition if it turns out to be true and which means that we failed in loading ggplot2 then I want you to run this command okay and this is a useful thing to do just okay now it’s annoying because you’re now potentially just changing the my machine okay but let’s assume that that’s that’s that’s okay so this is a this is a.

Good practice okay or at least having all the libraries at the top and then as for masking so if we actually do this let me.

Go over here and say gee here’s our and here’s library of ggplot2 a library of deep liar let’s just do that where are we getting and now the problem with library of deep liar is it says by the way deep liar is a package that we just loaded okay and it it defines filter and lag which are also in the stats package now.

When I now type filter as I got it from deep liar and I go like hang on a second I didn’t want the one in deep liar I wanted the one into the stats package so what’s the best practice for doing this in my code Harry let yourself okay but you know I might do library of deep liar or I do the if I do.

The if require of the prior installed apply or whatever it is in this case ggplot2 will install the pyre so I got the.

Dependent I don’t need to do this but if I do this now if I actually want to get the suppose now I want to actually compute the filter command filter of X of D dollar X okay well whatever it is okay if I wanted to do this it will pick the wrong.

Filter it’ll pick the one from deep liar and that may not.

Be what I wanted okay I’m just just for completeness I’m just I’m just using this as a random example but filter is actually in in deep liar filter well actually is an equivalent to subsetting you can they basically say filter.

Based on this condition in the in stats package filter.