How can I use function from xxx package in my package as member function.
1
0
Entering edit mode
6.0 years ago
Pijush Das ▴ 10

Hi,

I want to use a function as a ember function in my package which is already present in an existing package.

If I copy the code from that package and mention same name, it is producing some error. Though I have mention that where from the code is taken with proper formality but is is not working. Now when I change the function like functionName.XXX <- function( ) and put some alias{} name, it is working but when BiocCheck check is done it shows some kind of NOTE given below.

  • NOTE: Consider clarifying how 2 object(s) are initialized. Maybe they are part of a data set loaded with data(), or perhaps part of an object referenced in with() or within().

Please help me to solve this

regards pijush

R • 1.2k views
ADD COMMENT
2
Entering edit mode

Read about "Depends, Imports, Suggests", here and here.

ADD REPLY
1
Entering edit mode

In your roxygen2 docs for your function: #' @importFrom <packageName> <functionName>. In the body of your function: packageName::functionName(args)

ADD REPLY
1
Entering edit mode

I think either one should work, no? i.e. either #' @importFrom and then one should be able to use the function without the package name pre-prended or packageName::functionName()

ADD REPLY
0
Entering edit mode

I'd always put both. I certainly wouldn't use packageName::functionName without an @import - to keep my warnings down in R CMD check

ADD REPLY
0
Entering edit mode

Thank you so much Friederike, russhh and zx8754 for your kind help.

ADD REPLY
0
Entering edit mode

If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one answer if they work.
Upvote|Bookmark|Accept

ADD REPLY
1
Entering edit mode
6.0 years ago

a clean way to do is to:

  1. add package XXX to the Suggests: part of `DESCRIPTION, i.e.:

    Package: NewPackage
    Type: Package
    Title: < >
     ...
    Suggests:
        XXX
    
  2. use the function within your package using this notation: XXX::the_original_function_name()

If the function is not exported from XXX, you may need to use three instead of two colons.

This way you won't need to include the original code in your package, you keep the dependencies clean and you are also transparent about where that function was originally implemented.

ADD COMMENT
0
Entering edit mode

Thank you so much Friederike for your help.

I would like to draw your attention Friederike to my newly developed R package named "sigFeature". Though it is under review process, please find the link below. https://github.com/pijush1285/sigFeature I would be very much thankful if you give some valuable comments on it.

Thank you

regards Pijush

ADD REPLY
2
Entering edit mode

Pijush Das : You can create a post (with tool tag) if your package is reasonably complete. Include a brief description of how your package works, what it does and how to use it. Look at previous tools posts to see how you should structure the post.

ADD REPLY
1
Entering edit mode

Hi Pijush,

from a brief look at the repo structure everything looks like it should - anything in particular you would like to have double checked? Thumbs up for providing a vignette! You could actually check biostars whether there's already a way to a) promote your package while b) getting constructive feedback. I'd be interested to see if the community already has some suggestions as this is best handled.

ADD REPLY

Login before adding your answer.

Traffic: 1770 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6