2012-09-12 36 views
19

मैं कैसे इस तरह के रूप में कार्य करता ऊपर लिखा टिप्पणियों, के रूप में डेटा उदाहरण शामिल करने के लिए सीखने के लिए उत्सुक हूँ:आर संकुल को विकसित करने में डेटा उदाहरणों में शामिल हैं

##' @examples 
##' ## Set working directory... 
##' ## Load data into R session: 
##' data <- system.file("extdata", "data.txt", package="...", sep="\t", header=TRUE, stringsAsFactors = FALSE) 
##' 
##' ## For reproducible results: 
##' set.seed(999) 

मैं निर्देशिका में मेरे "data.txt" फाइल रख:/pkg_Name/Inst/extdata /। हालांकि, आर सीएमडी चेक इस चरण में त्रुटि इंगित करता है। यदि मैं आर सीएमडी बिल्ड और आर सीएमडी इंस्टॉल करने के लिए आगे बढ़ता हूं, तो पैकेज लोड करने के बाद, मुझे आर सत्र में डेटा नहीं मिल सकता है ... क्या कोई मुझे बता सकता है कि क्या गलत हुआ? क्या फ़ंक्शन सहायता दस्तावेज़ के अंत में डेटा उदाहरणों को शामिल करने का यह सही तरीका है?

बहुत बहुत धन्यवाद!

उत्तर

12

कृपया CRAN पैकेज देखें जिसमें डेटा शामिल है और उनके दृष्टिकोण की प्रतिलिपि बनाएँ। मैंने कुछ हफ्ते पहले एक ही काम-केवल पैकेज में डेटा जोड़ा और यह सिर्फ काम करता है ...

इसके लायक होने के लिए मैनुअल में एक अनुभाग 1.1.5 Data in packages है जो इसे समझाता है।

+0

सुझावों के लिए @ डिर्क धन्यवाद! – alittleboy

31

हैडली विकम ने पर अपनी पुस्तक how to incorporate data into an R Package पर एक अध्याय है।

data in packages पर आधिकारिक दस्तावेज़ीकरण के लिए Dirk अंक।

वैकल्पिक रूप से, यहां gdaplot2 पैकेज से सीखने का एक उदाहरण है कि आरडीए फाइलों और roxygen का उपयोग कर डेटा को कैसे शामिल किया जाए।

Here is the data directory in the ggplot2 package। इस उदाहरण में, प्रत्येक डेटा फ़ाइल एक अलग rda फ़ाइल में संग्रहीत किया जाता है (उदाहरण के लिए, उत्पन्न का उपयोग कर save(foo, file='foo.rda')

enter image description here

देखें the file data.r Roxygen डेटा के लिए आरएमडी मदद फ़ाइलों उत्पन्न करने के लिए आदेश के लिए:। उदाहरण के लिए,

#' Prices of 50,000 round cut diamonds 
#' 
#' A dataset containing the prices and other attributes of almost 54,000 
#' diamonds. The variables are as follows: 
#' 
#' @format A data frame with 53940 rows and 10 variables: 
#' \itemize{ 
#' \item price: price in US dollars (\$326--\$18,823) 
#' \item carat: weight of the diamond (0.2--5.01) 
#' \item cut: quality of the cut (Fair, Good, Very Good, Premium, Ideal) 
#' \item color: diamond colour, from J (worst) to D (best) 
#' \item clarity: a measurement of how clear the diamond is 
#'  (I1 (worst), SI1, SI2, VS1, VS2, VVS1, VVS2, IF (best)) 
#' \item x: length in mm (0--10.74) 
#' \item y: width in mm (0--58.9) 
#' \item z: depth in mm (0--31.8) 
#' \item depth: total depth percentage = z/mean(x, y) = 2 * z/(x + y) (43--79) 
#' \item table: width of top of diamond relative to widest point (43--95) 
#' } 
"diamonds" 
+8

ध्यान दें कि [पैकेज विकास पर हैडली की पुस्तक] (http://r-pkgs.had.co.nz) में अब पैकेज में डेटा जोड़ने के विभिन्न तरीकों पर एक अध्याय भी शामिल है: http: //r-pkgs.had .co.nz/data.html – jhin

+0

डेटासेट विवरण ['data.R'] (https://github.com/hadley/ggplot2/blob/master/R/data.R) में स्थानांतरित हो गए हैं। –

+0

@ रोमन लूस्ट्रिक धन्यवाद। मैंने जवाब को एक अद्यतन दिया। –