| len | supp | dose |
|---|---|---|
| 4.2 | VC | 0.5 |
| 11.5 | VC | 0.5 |
| 7.3 | VC | 0.5 |
| 5.8 | VC | 0.5 |
| 6.4 | VC | 0.5 |
| 10.0 | VC | 0.5 |
RaukR 2024 • Advanced R for Bioinformatics
Sebastian DiLorenzo
21-Jun-2024
r/DESCRIPTIONman/NAMESPACEdata/tests/src/ R CMD check


There are five states a package can exist in:
The development version of your package. The collection of files on your computer.
library(packagename) searches
.libPaths()When you use a package, it is in memory. When developing, a package does not have to be installed to be in memory.
packagename::function() loads packagename
library(packagename) loads and attaches packagename


library(), require(), source()options(), par()
0.0.0.9000
major.minor.patch.dev

call_me.R
#' Output "Call me " followed by input.
#'
#' @param x A character or characters.
#' @return The string "Call me " and \code{x}. I'll write this
#' to display how to section with tags.
#' @examples
#' call_me("Maeby")
call_me <- function(x) {
paste("Call me ", x, sep="")
}
Roxygen2
#', preceding a function@tags, map values@\%, escape with \call_me.R
#' Output "Call me " followed by input.
#'
#' @param x A character or characters.
#' @return The string "Call me " and \code{x}. I'll write this
#' to display how to section with tags.
#' @examples
#' call_me("Maeby")
call_me <- function(x) {
paste("Call me ", x, sep="")
}
call_me.Rd
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/call_me.R
\name{call_me}
\alias{call_me}
\title{Output "Call me " followed by input.}
\usage{
call_me(x)
}
\arguments{
\item{x}{A character or characters.}
}
\value{
The string "Call me " and \code{x}. I'll write this
to display how to section with tags.
}
\description{
Output "Call me " followed by input.
}
\examples{
call_me("Maeby")
}
]{.small}
> ?call_me


data.R:
#' The Effect of Vitamin C on Tooth Growth in Guinea Pigs
#'
#' The response is the length of odontoblasts (cells responsible for tooth growth)
#' in 60 guinea pigs. Each animal received one of three dose levels of vitamin C
#' (0.5, 1, and 2 mg/day) by one of two delivery methods, orange juice or ascorbic
#' acid (a form of vitamin C and coded as VC).
#'
#' @usage ToothGrowth
#'
#' @format A data frame with 60 observations on 3 variables.
#' \describe{
#' \item{len}{Tooth length}
#' \item{supp}{Supplement type (VC or OJ).}
#' \item{dose}{Dose in milligrams/day}
#' }
#' @source \url{https://www.elsevier.com/books/the-statistics-of-bioassay/bliss/978-1-4832-5662-7}
"ToothGrowth"
knitr & rmarkdown
knitr: add r code to markdownvignettes/package-vignette.Rmdusethis::use_vignette("typicalr-vignette")
typicalr-vignette.Rmd
---
title: "Vignette Title"
author: "Vignette Author"
date: "2024-05-29"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Vignette Title}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
knitr & rmarkdown
knitr: add r code to markdownvignettes/package-vignette.Rmdusethis::use_vignette("typicalr-vignette")
typicalr-vignette.Rmd
---
title: "typicalr"
author: "Sebastian DiLorenzo"
date: "2024-05-29"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{typicalr}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
package1 names package2 names
@imports and @importsFrom
@imports pkg@importsFrom pkg function@export
call_me.R:
#' Output "Call me " followed by input.
#'
#' @param x A character or characters.
#' @return The string "Call me " and \code{x}. I'll write this
#' to display how to section with tags.
#' @examples
#' call_me("Maeby")
#' @export
call_me <- function(x) {
paste("Call me ",x,sep="")
}
utility.R:
#' @import knitr
NULL
NAMESPACE:
# Generated by roxygen2: do not edit by hand
export(call_me)
import(knitr)
Import in DESCRIPTION and in NAMESPACE!?
Imports:
@import
::
package::function() or function()Package types:
Data types:
.Rdata or .rda
data/ folderR/sysdata.rda.xlsx,.csv etc
inst/extdatafolder# Create data in package automatically
usethis::use_data(object, package)
# Manually
save(object, file="path/to/package/data/object.Rdata")
# Access raw data
system.file("extdata","filename.csv", package="packagename")

testthat package for testing and usethis package for setup use_testthat()use_test("call_me")tests/testthat/test-call_me.Rdevtools::test() or check()tests/testthat/test-call_me.R:
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})
RcpprJavainst/usethis::use_rcpp()
#' @useDynLib packagename#' @importFrom Rcpp sourceCpp.cpp file in src/src/filename.cpp:
#include <Rcpp.h>
using namespace Rcpp;
// This is a simple example of exporting a C++ function to R. You can
// source this function into an R session using the Rcpp::sourceCpp
// function (or via the Source button on the editor toolbar). Learn
// more about Rcpp at:
//
// http://www.rcpp.org/
// http://adv-r.had.co.nz/Rcpp.html
// http://gallery.rcpp.org/
//
// [[Rcpp::export]]
NumericVector timesTwo(NumericVector x) {
return x * 2;
}
RcpprJavainst/usethis::use_rcpp()
#' @useDynLib packagename#' @importFrom Rcpp sourceCpp.cpp file in src/pkgbuild::compile_dll()devtools::document()Build & Reload.cppR/RcppExports.R:
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
timesTwo <- function(x) {
.Call('_typicalr_timesTwo', PACKAGE = 'typicalr', x)
}
R CMD checkR CMD check
devtools::check()git
devtools::install_github()
R CMD check.github/workflows/workflow-name.yamlpushr/DESCRIPTIONman/NAMESPACEdata/tests/src/ R CMD check _
platform x86_64-pc-linux-gnu
os linux-gnu
major 4
minor 3.2
2024 • SciLifeLab • NBIS • RaukR