0

I am creating an R package and now working on the NEWS file. I have an .Rd file in the inst subfolder which I would like to be called by a customised function like my_pckg_news(). I saw this in the gamlss package which has gamlssNews() as the customised function that calls a NEWS.txt file.

So could I create a similar function such that, when calling this function shall display the NEWS.Rd file in the help section of RStudio? the way we have ?function_name displaying the respective Rd file.

Edit : added the sample .Rd file

\name{my_package}
\title{News for package \pkg{my_package}}

\section{}{
  \itemize{ 
    \item item1
  }       
}


\section{Version 0.1}{
  \subsection{f1}{
    \itemize{
      \item item1
      \item item2
    }
  }
  \subsection{f2}{
    \itemize{
      \item item1
    }
  }
}

Another problem I'm facing here is that, f1 , f2 doesn't get printed . and this file doesn't get loaded on the Help section(of RStudio) , rather gets directly printed to the R console

joel.wilson
  • 8,243
  • 5
  • 28
  • 48
  • How is the file formatted? You should probably just include it in your question. – nrussell May 08 '17 at 10:25
  • I suppose the `.Rd` file, as that is probably what needs to be shipped with your package. – nrussell May 08 '17 at 10:55
  • 1
    Your sample `NEWS.Rd` [worked for me](https://github.com/nathan-russell/news/blob/master/README.md). Are you able to reproduce the problem with my example package? – nrussell May 09 '17 at 11:50
  • The `Writing R Extensions` suggest that we should have it in `inst` subfolder. Let me try it – joel.wilson May 09 '17 at 14:42
  • 1
    I have it in the `inst/` folder -- I think that is the only acceptable location for `NEWS.Rd`. – nrussell May 09 '17 at 14:51
  • @nrussell i have it now in `inst` folder and it gets attached. But it doesnt get loaded in the help section but gets printed on the `R` console itself. How can we have it displayed on the help section itself ? Would you like to ask a new questoin itself if I'm bothering you a lot? – joel.wilson May 09 '17 at 17:04
  • No it's fine -- it sounds like the issue might be with `utils:::print.news_db` instead of `news` itself. I believe that is the function actually responsible for rendering the news document. Have you had issues with any other help files, etc. not rendering? – nrussell May 09 '17 at 17:11
  • 1
    @nrussell i was able to solve the problem... thank you very much for the support! – joel.wilson May 10 '17 at 11:00

1 Answers1

1

after some reading, trials(many!) and help from @nrussell, i was able to have a customised functions for my news file .

In brief :

  1. create a inst subfolder in your main directory( where DESCRIPTION etc) files exist.

  2. inside the inst folder create another subfolder doc wherein you shall save your NEWS.txt file.

  3. Now create a .R file with the name of function you want to keep as the customised news function which when called shall display the NEWS file. You can have this filename as a alias in one of the .Rd filew so that you need not create a separate .Rd file for this

  4. Inside this function write a single line code that loads the .txt file. file.show(system.file("doc", "NEWS.txt", package = "your_pckg_name"))

  5. Also try to build .onAttach() function such as to display a welcoming message when your package gets loaded. Herein you can also mention the name of your customised news function.

  6. Final result : = call your news function!!!!

Hope this helps future users!

joel.wilson
  • 8,243
  • 5
  • 28
  • 48