Internal and External dataset

I need some clarification about usage of datasets within a package. I want to export dataset but also use it internally within a package function. Exporting dataset works, but when I try to use it within a function with:

utils::data("my_df", package = "my_pacakge", envir = environment())

and use devtools::check() I get:

some function in package: no visible binding for global variable 'my_df' Undefined global functions or variables: my_df

How to export dataset but also use it within functions in package?

1 Like

My go-to whenever I need to add data to a package is the chapter Data from R Packages. However, it makes a clear distinction between external and internal data sets; whereas, you want to use the data for both use cases. I recommend reading through it for ideas.

Off the top of my head, one idea would be to put the data set in inst/. Then you could load the data inside your package functions with system.file(), and you could provide the end users with a convenience function to load this data. This would lose some of the convenience of using the built-in system via utils::data(), but it would give you more flexibility as the package author.

Thanks for feedback. I always look into book whenever I have pacakge development related questions. It's really great and I love search option. I've read that chapter but didnt manage to find something regarding using dataset internally and exporting it at same time.

I'm interesed in 'good practice' solution, and your suggestions seems to be one.

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.