R Package Modification

Hi Everyone,

I am currently dealing with a R package that has a built in dataset. My aim is to utilize this package on a dataset of my own making.

Do I need to rebuild the package from scratch using my dataset or is there a simple-ish workaround (I am an R novice)? Some users online have said this can be easily done via my global environment, others say obtaining source code is required.

Any ideas/pointers gratefully appreciated.

Thanks in advance


A package that only works with a built-in dataset would be extremely rare and most likely useless. Packages implement functions that can be executed over input data provided by the user, they usually include some sample data (built-in data) as a mean of easy demonstration of their functionality but they are not limited to work with that particular data.

We don't really have enough information to help you, to help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:


Yes, thank you for the reply - my apologies for the poorly phrased post, as I say I am new to the R community.

As you say functions within R packages can be executed over input data however when I try to run a function on a dataset I have imported and attached I get 'Error: object can not be found'.

factors <- read.delim("C://FX/factors.txt")
rm(list = ls())
Warning message:
In data("factors") : data set ‘factors’ not found
datdf = factors;
Error: object 'factors' not found

Thanks in advance


The data() function is from base R (not a loaded package) and it is not meant to be used that way, it is used to load built-in datasets into your working environment, so in your case there is no reason to use it.

If you could better explain what your goal is and provide a proper reprex we might be able to help you.

1 Like

@AlanConnell5 as underlined by @andresrcs we'd be better able to help with a reprex but in the meantime, based on your code snippet here are some helpful references.

  • Using rm(list = ls()) is not recommended. See this blog post about project-oriented workflow.
  • Using attach() is not recommended either, I found a thread collecting horror stories. Now I also vaguely remember it's more common with other tools so I'm not being snarky, we were all R beginners once.
    In general when you want to use a package coolpkg on your own data and the documentation has something like

You in your code will have something like

my_data <- readr::read_delim(<relative-path-to-data>)

Here are two websites listing general resources for learning R

Good luck!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.