Problems importing a R package from Github into a new jamovi module

Everything related to the development of modules in jamovi
Anna9
Posts: 11
Joined: Mon Mar 27, 2023 2:12 pm

Problems importing a R package from Github into a new jamovi module

Post by Anna9 »

Good evening, I am building a module of jamovi which requires importing the rnaturalearthhires package from Github, but I have some problems importing it. At the moment, I wrote the following code in the DESCRIPTION file, to import the package:

Code: Select all

Remotes: ropensci/rnaturalearthhires
Imports: jmvcore (>= 0.8.5), R6, ggplot2, dplyr, remotes, rnaturalearth, rnaturalearthdata, rnaturalearthhires  

When I used jmvtools::install(), the command worked but I managed to only partially import rnaturalearthhires. Indeed, some folders of the package (e.g. the data folder) are missing. For this reason, I cannot create maps.
I have noticed that, if I load the rnaturalearthhires package in R Studio, and then I copy and paste the rnaturalearthhires folder into the folder of the installed R packages of the new jamovi module, then I can create maps. However, I would like to properly import the package using code. Could you please help me understand how I can solve this problem?
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Problems importing a R package from Github into a new jamovi module

Post by jonathon »

hi,

so the intention with the data folder is that it contains data sets that a person might play around with interactively ... usually for demonstrating how to use an R package. oftentimes you don't care about using the included data, and you just want to use the package (or the package is used as a dependency) and so R has the option to install packages without data. the argument is --no-data, and is used as follows:

R CMD INSTALL --no-data packageName

so this is what jamovi is doing. installing like this shouldn't be a problem for the packages function.

if it *is* a problem, that the data is intrinsic to the function of the package, i don't think the package author should be deploying it with the data system, but rather should be putting them in the 'inst' folder instead.

i'd reach out to the rnaturalearthhires package and see what they think.

if they're not interested in addressing this, we might be able to suppress the --no-data argument when installing rnaturalearthhires, but a) i don't think it's our problem b) it would annoy me ... but we could do it.

cheers

jonathon
Anna9
Posts: 11
Joined: Mon Mar 27, 2023 2:12 pm

Re: Problems importing a R package from Github into a new jamovi module

Post by Anna9 »

Hi,

thank you very much for your help. I think the data in rnaturalearthhires are required for high resolution maps. Do you suggest me to reach out to the authors of the rnaturaearthhires package to confirm this?

About the second option, how could I do to suppress the --no-data argument?
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Problems importing a R package from Github into a new jamovi module

Post by jonathon »

> I think the data in rnaturalearthhires are required for high resolution maps

yes. however if they are required for the function of the package, i would suggest they should be placed in inst, rather than data. this ensures that the package continues to function, even when installed with the --no-data option. i would suggest this to the authors of rnaturalearthhires.

> how could I do to suppress the --no-data argument?

this would require us to add a hack into jmvtools to handle the rnaturalearthhires package in a special way ... which obviously i don't feel like we should have to do, but i can look into it. contact the rnaturalearthhires author first. if they can fix the package, then we don't have to do anything ... if they don't want to ... well i can look into it.

jonathon
Anna9
Posts: 11
Joined: Mon Mar 27, 2023 2:12 pm

Re: Problems importing a R package from Github into a new jamovi module

Post by Anna9 »

Hi,

thank you, I have reached out to the authors of rnaturalearthhires. They suggested first to use the command rnaturalearth::ne_download(), which directly downloads data from the website of rnaturalearth. In this way, I don't have to have the rnaturalearthhires package installed to make maps.

I have some issues using the command ne_download() in jamovi.
An error message appears, like:

"Error in utils::download.file(file.path(address), zipfile <- tempfile()): cannot open URL..."

How does a jamovi module download data from a website? In this case, does it use utils::download.file(...), even if I am using a diffferent command (ne_download)?
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Problems importing a R package from Github into a new jamovi module

Post by jonathon »

They suggested first to use the command rnaturalearth::ne_download()
i think this is a superficially reasonable suggestion, but i don't think it will work.
How does a jamovi module download data from a website?
in this instance, it's not jamovi, but rather R doing the download. now why R behaves differently in this context i couldn't say ...

but you don't have to worry about it ... i've added special code which detects whether rnaturalearth is being installed, and suppresses the --no-data argument ... if you update your jmvtools, you should be in business.

jonathon
Anna9
Posts: 11
Joined: Mon Mar 27, 2023 2:12 pm

Re: Problems importing a R package from Github into a new jamovi module

Post by Anna9 »

Hi,

thank you very much, I will try to update jmvtools and see if it works. I would like to ask some questions about the library:

- after updating jmvtools, do I have to create my package again, or just run jmvtools::install()?
- does the exception to --no-data only refers to rnaturalearth? If rnaturalearthhires requires data, are these installed too?
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Problems importing a R package from Github into a new jamovi module

Post by jonathon »

after updating jmvtools, do I have to create my package again, or just run jmvtools::install()
delete the build folder from your module, and then it will pull down rnaturalearth afresh without the --no-data argument.
does the exception to --no-data only refers to rnaturalearth? If rnaturalearthhires requires data, are these installed too?
so the fix is rather crude ... if the list of packages being installed contains rnaturalearth, it suppresses the --no-data argument ... so depending on the order that you add and install dependencies, other packages may or may not be installed with the --no-data argument.

rnaturalearthhires has the same problem?

i'll add it to the "suppress --no-data list", and that will go out in the a future release ... for now, provided rnaturalearth and rnaturalearthhires are installed at the same time, they'll both be installed with --no-data.

jonathon
Anna9
Posts: 11
Joined: Mon Mar 27, 2023 2:12 pm

Re: Problems importing a R package from Github into a new jamovi module

Post by Anna9 »

Hi,

thank you very much. I tried to delete the build folder but unfortunately I have the same problem: for the rnaturalearthhires package, the data folder is missing, as well as the help folder and the html folder, and I cannot make maps. Jamovi gives the following error message: 'states10 is not an exported object from namespace:rnaturalearthhires'. Maybe I made some mistakes in the DESCRIPTION file?

In the Github of rnaturalearthhires, it reports that the following code should be used to install this package in R:

Code: Select all

remotes::install_github("ropensci/rnaturalearthhires")
install.packages("rnaturalearthhires", repos = "https://ropensci.r-universe.dev", type = "source")
Based on the code above, I added the following code in the DESCRIPTION file of my jamovi module :

Code: Select all

Remotes: ropensci/rnaturalearthhires
Imports: jmvcore (>= 0.8.5), R6, ggplot2, dplyr, remotes, rnaturalearth, rnaturalearthdata, rnaturalearthhires 
Do I have to modify the DESCRIPTION file?
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Problems importing a R package from Github into a new jamovi module

Post by jonathon »

so it is working for rnaturalearth, but not rnaturalearthhires?

if you add both rnaturalearth *AND* rnaturalearthhires to imports, delete the build folder, run jmvtools::install(), you should find it will include the data for both.

kind regards
Post Reply