New series "Little-known useful R functions #1: lookup() from {lookup}"

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello i think i will start a new series where i discuss functions that are not very well known and i might do that once a week or twice a week depends a bit on my schedule but the idea would be to present functions that are not very well known from packages that are i guess not released on cram yet or if they are still very niche something that is maybe just solving one particular issue but that i find very useful and [Music] i today what i will show you is the lookup function from the lookup package that you can find on github so i will link that github link in the description it's a package made by jim hasta i think he's a software engineer in at our studio and it's a very nice package so let's see what it does so imagine that you are working in r and you want to look at the source code of a function so what you can do in r um is for example imagine that i'm working with the janitor package and i i want to know how the table function works so here you see that if i write table without any parentheses i should be seeing the source code but what i see what i see instead is this use method table let's try maybe with some base function yeah this one also shows you primitive sqrt square root so you don't you're not seeing any source code um i guess you know if you use any of this base function you'll have the same result because all these functions i i think are um what's happening here is that it's not r codes they're not written in r they're written in c or fortran or something like that you can find functions that are written in pure r so if you just write the um the function name without any parentheses you will you will um you will be able to read the source code okay i don't know if we can find any like that um easily maybe no everything that is based i'm not sure i mean i think it's all compiled um anyway i i don't think even mean that's for sure yeah mean is also use method meat so you can't read the source code of these now if you download the package from for example if you don't one of my of my packages that i've i've written that contains some of my helper functions that i use for for example my my blog team so when i do a gg plot i have this theme that i've written that goes well with my blog so this is pure r so if you write the name of the function without parentheses you'll be able to read the source code but what do you do about this what if you want to read source code of table of square root etc well the lookup package that you can install from github is here to help so this package has a function called lookup and what it does is that it looks up where the source code is uh for example if i go with let's call it ask sqrt and it will fetch the code so i think it goes online to get the code so um i think it downloads it from from from some repository i guess um anyway you see here the c source code to the square root function so i just wrote look up square roots i had to wait a little bit and now i have uh so this um the function is defined in the source file called arithmetic.c and uh that's here it is okay so if you if you're not uh familiar with c this maybe is not very helpful but if you are familiar with c then you can read that you understand where it's coming from etc um i guess here in this case from like i haven't done a lot of c in a lot of time but this seems to be something uh so it doesn't seem to be like the source code of square root itself but it seems to be a bit more complex here so i don't know if you could really go to one of my cats is uh throwing up great and anyway that's all i want to show you so i have to clean that mess but yeah if you if you're writing something like uh so let's go back to the janitor table function um so you're asking which s3 method because you have a table for data frames and you have to build default which i guess uh is maybe for matrices i don't know so let's go with all and here you can see the source code so this is pure uh r code so here you can scroll up and you can read okay so that's the definition of the function that you couldn't read before so yeah i guess it's more helpful but if it's pure c and you're not familiar with c and even here actually um if i go back to my square root function i think it's even more nested than that because this does not look like it's it's returning the source code of square root but rather the source code of another function that calls square root if you're calling square root but it will call exponential if you're if you want exponential and so on so i don't think this is yeah very helpful for this example but here for table you see now you get the um the r source code so that's all i want to show you look up uh i'll link it in the description take a look at it i think it's quite useful can really be helpful in if you want to read source code of some functions and yeah i guess i'll be doing short videos where i present just one function more and more maybe twice once or twice a week we'll see and i'll try to focus on as i said functions that are not well known for packages that are not well known but quite useful and by not well known one of these criteria is uh it's not on trend but maybe some will be on cram we'll see anyway have a good one and see you next time
Info
Channel: Bruno Rodrigues
Views: 484
Rating: 5 out of 5
Keywords: rstats, little known useful functions
Id: _GpzvW7hOTs
Channel Id: undefined
Length: 6min 11sec (371 seconds)
Published: Tue May 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.