---
title: How to identify which packages (and which functions) are actually being used by an R file | Hartley McMaster
description: Discover how to use RDocumentation to search all the packages and functions referenced in an R file, even if they’re not loaded. Plus learn what that means for your own work.
image: https://blog.hmcm.co.uk/hubfs/how-to-dentify-r-packages.png
---

[Skip to the main content.](https://blog.hmcm.co.uk/insights/how-to-identify-which-packages-and-which-functions-are-actually-being-used-by-an-r-file#main-content)

[![HMCM logo two-colour STANDARD](https://blog.hmcm.co.uk/hs-fs/hubfs/logos/HMCM%20logo%20two-colour%20STANDARD.png?width=3125&height=1000&name=HMCM%20logo%20two-colour%20STANDARD.png "HMCM logo two-colour STANDARD")](https://www.hmcm.co.uk)

[![HMCM logo two-colour STANDARD](https://blog.hmcm.co.uk/hs-fs/hubfs/logos/HMCM%20logo%20two-colour%20STANDARD.png?width=3125&height=1000&name=HMCM%20logo%20two-colour%20STANDARD.png "HMCM logo two-colour STANDARD")](https://www.hmcm.co.uk)

- [Tel: +44 (0)20 4583 4513](tel:+442045834513)
- [Company](https://www.hmcm.co.uk/company)
- [Insights](https://blog.hmcm.co.uk/insights)
- [Contact Us](https://meetings-eu1.hubspot.com/tom-dewar/web-enquiry)

[![Request my free data review](https://hubspot-no-cache-eu1-prod.s3.amazonaws.com/cta/default/25327253/0acd864d-b25e-45d9-9827-af55d4ac0405.png)](https://hubspot-cta-redirect-eu1-prod.s3.amazonaws.com/cta/redirect/25327253/0acd864d-b25e-45d9-9827-af55d4ac0405)

Toggle Menu

Toggle Menu

[![Request my free data review](https://hubspot-no-cache-eu1-prod.s3.amazonaws.com/cta/default/25327253/0acd864d-b25e-45d9-9827-af55d4ac0405.png)](https://hubspot-cta-redirect-eu1-prod.s3.amazonaws.com/cta/redirect/25327253/0acd864d-b25e-45d9-9827-af55d4ac0405)

- [Tel: +44 (0)20 4583 4513](tel:+442045834513)
- [Company](https://www.hmcm.co.uk/company)
- [Insights](https://blog.hmcm.co.uk/insights)
- [Contact Us](https://meetings-eu1.hubspot.com/tom-dewar/web-enquiry)

[*Facebook*](https://blog.hmcm.co.uk/insights/how-to-identify-which-packages-and-which-functions-are-actually-being-used-by-an-r-file#0) [*Instagram*](https://blog.hmcm.co.uk/insights/how-to-identify-which-packages-and-which-functions-are-actually-being-used-by-an-r-file#0) [*LinkedIn*](https://blog.hmcm.co.uk/insights/how-to-identify-which-packages-and-which-functions-are-actually-being-used-by-an-r-file#0) [*Twitter*](https://blog.hmcm.co.uk/insights/how-to-identify-which-packages-and-which-functions-are-actually-being-used-by-an-r-file#0) [*Youtube*](https://blog.hmcm.co.uk/insights/how-to-identify-which-packages-and-which-functions-are-actually-being-used-by-an-r-file#0) [*Medium*](https://blog.hmcm.co.uk/insights/how-to-identify-which-packages-and-which-functions-are-actually-being-used-by-an-r-file#0)

##### Column Headline

- Testing 1 
    - Sub Nav 1
    - Sub Nav 2
- Testing 2
- Testing 3

##### Column Headline

- Testing 1 
    - Sub Nav 1
    - Sub Nav 2
- Testing 2
- Testing 3

<script charset="utf-8" type="text/javascript" src="//js-eu1.hsforms.net/forms/v2.js?pre=1"></script>  
<script>  
  hbspt.forms.create({  
    region: "eu1",  
    portalId: "25327253",  
    formId: "7b54ff23-6bb2-451e-b75c-cb757c99451d"  
  });  
</script>

- Testing 1 
    - Sub Nav 1
    - Sub Nav 2
- Testing 2
- Testing 3

 1 min read

# How to identify which packages (and which functions) are actually being used by an R file

[![Picture of Tom Dewar](https://app.hubspot.com/settings/avatar/b623ffbedbcfa0e304efa678b0218d48) Tom Dewar](https://blog.hmcm.co.uk/insights/author/tom-dewar)  Mar 2020

[technical tips](https://blog.hmcm.co.uk/insights/tag/technical-tips)

![How to identify which packages (and which functions) are actually being used by an R file](https://blog.hmcm.co.uk/hubfs/how-to-dentify-r-packages.png)

When inheriting someone else’s R code, I always like to check which packages and functions it uses. Not just those it loads with library function calls, but those it actually uses. To this end I recently discovered [this useful little utility](https://www.rdocumentation.org/packages/NCmisc/versions/1.1.6/topics/list.functions.in.file) which will provide you a list of all the packages and all the functions within those packages referenced in a given R file.

The package you will need to install is **NCmisc**, and the function we are going to use within it is the aptly named **list.functions.in.file**.

![1](https://blog.hmcm.co.uk/hs-fs/hubfs/1.png?width=628&name=1.png)

Example use of NCmisc::list.functions.in.file()

It works by identifying all the function calls in the given file and comparing these to functions currently loaded in memory.

This means that before running **list.functions.in.file** you will need to have loaded into memory all the packages you believe are referenced, and only those packages. The easiest way to do this is to open a fresh instance of RStudio and just execute the code in the file. (In the example above, the “global.R” file is part of a Shiny app which I first ran, then stopped.)

The output is a named list. Each item is named for the name of the package, or packages (plural) if a particular function name is common to more than one package. Each list entry is a list of function names. Any custom functions defined in the file itself will appear under **.GlobalEnv**.

If your R script file loads a package, but that package is **not** listed in this output, it is redundant and you can remove it. Decluttering is good.

In our example there are five functions referenced in this file which hail from the **plotly** package. But there is another one — the **layout** function — which is defined in both plotly and **graphics**.

![2](https://blog.hmcm.co.uk/hs-fs/hubfs/2.png?width=628&name=2.png)

 

#### Finding potential function name clashes

So this can be a tool to spot potential namespace conflicts. I happen to know we don’t need to worry about this *particular* clash, but that will not always be the case. In this same example, there is a function called **get** in the **config** package which clashes with a completely different base function of the same name.

![3](https://blog.hmcm.co.uk/hs-fs/hubfs/3.png?width=628&name=3.png)

Even with the **config** package loaded, we should always call its **get** function with an explicit reference — using the double-colon notation — to avoid unintended consequences.

![4](https://blog.hmcm.co.uk/hs-fs/hubfs/4.png?width=628&name=4.png)

And that’s it. You are of course free to wrap this in your own code if you want it to parse through multiple files, look for specific packages / functions, output results to a text file etc.

- [Tweet](https://twitter.com/share)

[![Connecting Posit Workbench (RStudio) to GitHub with HTTPS](https://blog.hmcm.co.uk/hubfs/blog/posit-github-https/github-posit3.png)](https://blog.hmcm.co.uk/insights/connecting-posit-workbench-to-github-with-https)

#### [Connecting Posit Workbench (RStudio) to GitHub with HTTPS](https://blog.hmcm.co.uk/insights/connecting-posit-workbench-to-github-with-https)

![Picture of Tom Dewar](https://app.hubspot.com/settings/avatar/b623ffbedbcfa0e304efa678b0218d48) [Tom Dewar](https://blog.hmcm.co.uk/insights/author/tom-dewar): Mar 2023

If you're an RStudio user using Posit Workbench and want to use GitHub for source control (you should), this is the guide for you. There are two ways...

[technical tips](https://blog.hmcm.co.uk/insights/tag/technical-tips) 

[Read More](https://blog.hmcm.co.uk/insights/connecting-posit-workbench-to-github-with-https)

[![How to maxmise value from data analytics](https://blog.hmcm.co.uk/hubfs/blog%20charts/illustrative_graph_blue_orange.jpeg)](https://blog.hmcm.co.uk/insights/maximise-value-from-data-analytics)

#### [How to maxmise value from data analytics](https://blog.hmcm.co.uk/insights/maximise-value-from-data-analytics)

![Picture of Tom Dewar](https://app.hubspot.com/settings/avatar/b623ffbedbcfa0e304efa678b0218d48) [Tom Dewar](https://blog.hmcm.co.uk/insights/author/tom-dewar): Mar 2023

Many companies investing in data analytics struggle to achieve the full value of their investment, perhaps even becoming disillusioned. To understand...

[data leadership](https://blog.hmcm.co.uk/insights/tag/data-leadership) 

[Read More](https://blog.hmcm.co.uk/insights/maximise-value-from-data-analytics)

[![Five ways data can help your business navigate stormy waters](https://blog.hmcm.co.uk/hubfs/stormy-seas-1.jpg)](https://blog.hmcm.co.uk/insights/five-ways-data-can-help-your-business-navigate-stormy-waters)

#### [Five ways data can help your business navigate stormy waters](https://blog.hmcm.co.uk/insights/five-ways-data-can-help-your-business-navigate-stormy-waters)

![Picture of Tom Dewar](https://app.hubspot.com/settings/avatar/b623ffbedbcfa0e304efa678b0218d48) [Tom Dewar](https://blog.hmcm.co.uk/insights/author/tom-dewar): Oct 2022

We are cursed to live in interesting times. As I write this, a war in Ukraine rumbles on, we sit on the tail of a pandemic and at the jaws of a...

[data leadership](https://blog.hmcm.co.uk/insights/tag/data-leadership) 

[Read More](https://blog.hmcm.co.uk/insights/five-ways-data-can-help-your-business-navigate-stormy-waters)

##### Get our latest insights

Get our latest insights

Hartley McMaster is an independent management consultancy specialising in the use of analytical and structured methods to solve business problems.

 

##### London

London

167-169 Great Portland Street  
5th Floor  
London, W1W 5PF  
United Kingdom

T: +44 (0) 20 4583 4513

[E: contact@hmcm.co.uk](mailto:contact@hmcm.co.uk)

##### Hong Kong

Hong Kong

1104 Crawford House  
70 Queen's Road Central  
Central  
Hong Kong

T: +(852) 5346 5400

[E: contact@hmcm.com.hk](mailto:contact@hmcm.com.hk)

[![HMCM logo two-colour REVERSED](https://blog.hmcm.co.uk/hubfs/logos/HMCM%20logo%20two-colour%20REVERSED.png)](https://www.hmcm.co.uk)

- [Privacy Policy](https://www.hmcm.co.uk/privacy-policy)

© 2026 Hartley McMaster Ltd

[*Twitter*](https://twitter.com/hartleymcmaster)[*LinkedIn*](https://www.linkedin.com/company/hartley-mcmaster/) 

*Return to Top*

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Tom Dewar",
    "url" : "https://blog.hmcm.co.uk/insights/author/tom-dewar"
  },
  "dateModified" : "2022-09-20T07:50:15.594Z",
  "datePublished" : "2020-03-30T08:00:00.000Z",
  "headline" : "How to identify which packages (and which functions) are actually being used by an R file | Hartley McMaster",
  "image" : [ "https://blog.hmcm.co.uk/hubfs/how-to-dentify-r-packages.png" ],
  "mainEntityOfPage" : {
    "@id" : "https://blog.hmcm.co.uk/insights/how-to-identify-which-packages-and-which-functions-are-actually-being-used-by-an-r-file",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://blog.hmcm.co.uk/hubfs/logos/HMCM%20logo%20two-colour%20STANDARD%20100h.png"
    },
    "name" : "Hartley McMaster Ltd"
  }
}
```