0

I have a R script that calls the updatePackages() function in MiniCRAN which in turn calls these functions:

updatePackages (miniCRAN) -> oldPackages (miniCRAN) -> pkgAvail (miniCRAN) -> read.dcf (base)

I wish to create my custom read.dcf function that slightly modifies the original read.dcf function and so that when it's run the pkgAvail function will call my custom read.dcf instead of the default read.dcf function. I've defined the function in my script before running the updatePackages function:

read.dcf <- function(file,...) { my modified code }

...

library(miniCRAN); updatePackages();

But when I ran the script it's still giving me the same error that suggests the original read.dcf function was still being called. Do I have to do anything extra in my code to ensure this particular read.dcf function is called by oldPackages? What would be the easiest way to make this work?

Thanks

user9367574
  • 91
  • 1
  • 7
  • 1
    If you want this to work in a consistent and non-hacky way, I would probably start a new project in R studio, select "Version Control", select "Git", put https://github.com/andrie/miniCRAN as the repository URL, then hit "create project". You will get the whole package source downloaded into a local folder. Navigate to R/updatePackages.R where you will find the OldPackages function. Modify it as you see fit, then select "clean and rebuild" from the "Build" item in the menu bar. This will install _your_ version of miniCRAN, so whenever you call `library(miniCRAN)` you get your version of it. – Allan Cameron Apr 01 '22 at 19:07
  • Hi Allan, the function read.dcf() I'm trying to edit is actually not a miniCRAN function. I believe it's a base R function. Are you suggesting I clone the miniCRAN repo, open up the pkgAvail.R function in the miniCRAN repository, define my own read.dcf function there and modify the pkgAvail function to call my custom function? – user9367574 Apr 01 '22 at 20:27
  • How exactly are you running the file/calling the function? What does `environment(read.dcf)` return before calling the function? Does the problem disappear when you don't call `updatePackages`? or how is that related? If the function is not called by your code, but called by code in other packages, it will not see your version in the global environment. It's really hard to offer specific help without any sort of [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick Apr 02 '22 at 01:02

1 Answers1

0

So turns out pkgAvail calls utils::available.packages, and I need to modify the utils.available.packages. So I downloaded the miniCRAN project, defined a new function called available_packages inside pkgDep.R file which contains the pkgAvail function, modified the pkgAvail function so it calls my own available_packages, and then "clean and rebuild" the new miniCRAN project.

user9367574
  • 91
  • 1
  • 7