Writing R package functions to create an API to command-line tools

api
package
Tags: #<Tag:0x00007f5db21fa420> #<Tag:0x00007f5db21fa2b8>
#1

Hi,

I am currently developing an R package and I want one of the functions to wrap a command-line tool to create an API to this tool. I am somewhat new to R package dev so I am running into a few issues that may be easy for some of you to solve, but I haven’t found an adequate solution yet.

  1. When I am using the terminal on my Mac and type 'which toolname ’ I am able to locate the path to the executable for a given tool. However, when I invoke the system() function in R, for example, system(‘which toolname’), the path is not found. I am assuming has to do with the PATH variable in my bash_profile which R does not seem to be finding/searching. Any idea how to get R to search PATH to find the CLI tool?

  2. As a possible circumvention of this issue, I am considering having users of my package provide the path to the CLI tool manually, just once, and storing that path internally in the package for future use. Is it possible to have a function that takes a path to an executable as an argument and then stores the path internally so that it can be called each time the package is loaded?

Thank you for your help.

1 Like
#2

Hi @mattwarkentin, Thanks for asking your question here.
I don’t know the answer to your question, but in case you don’t get an answer from someone right away, here is a post by @maelle that might help https://masalmon.eu/2018/07/22/wheretogethelp/

Cheers

1 Like
#3

:wave: @mattwarkentin!

I subscribed to RStudio community package development category so saw your post there, where I see you’ve already got useful answers.

I assume your package depends on such a tool because there’s no way around it? E.g. no C library for the tool (e.g. the magick package wraps the magick C library, not the ImageMagick command line tool)?

There are a few packages in our suite calling command-line tools, among which one I can think of at the moment :see_no_evil:

  • nlrx see in particular this function. The package has a function helping the user download the tool. I have not looked thoroughly enough to find how the path to the NetLogo install is stored or not, but I saw it as an argument to some functions.
2 Likes