बस अपनी फ़ाइल पर readLines
का उपयोग करें:: इस कोड है
R> res <- readLines(system.file("DESCRIPTION", package="MASS"))
R> length(res)
[1] 27
R> res
[1] "Package: MASS"
[2] "Priority: recommended"
[3] "Version: 7.3-18"
[4] "Date: 2012-05-28"
[5] "Revision: $Rev: 3167 $"
[6] "Depends: R (>= 2.14.0), grDevices, graphics, stats, utils"
[7] "Suggests: lattice, nlme, nnet, survival"
[8] "[email protected]: c(person(\"Brian\", \"Ripley\", role = c(\"aut\", \"cre\", \"cph\"),"
[9] " email = \"[email protected]\"), person(\"Kurt\", \"Hornik\", role"
[10] " = \"trl\", comment = \"partial port ca 1998\"), person(\"Albrecht\","
[11] " \"Gebhardt\", role = \"trl\", comment = \"partial port ca 1998\"),"
[12] " person(\"David\", \"Firth\", role = \"ctb\"))"
[13] "Description: Functions and datasets to support Venables and Ripley,"
[14] " 'Modern Applied Statistics with S' (4th edition, 2002)."
[15] "Title: Support Functions and Datasets for Venables and Ripley's MASS"
[16] "License: GPL-2 | GPL-3"
[17] "URL: http://www.stats.ox.ac.uk/pub/MASS4/"
[18] "LazyData: yes"
[19] "Packaged: 2012-05-28 08:47:38 UTC; ripley"
[20] "Author: Brian Ripley [aut, cre, cph], Kurt Hornik [trl] (partial port"
[21] " ca 1998), Albrecht Gebhardt [trl] (partial port ca 1998), David"
[22] " Firth [ctb]"
[23] "Maintainer: Brian Ripley <[email protected]>"
[24] "Repository: CRAN"
[25] "Date/Publication: 2012-05-28 08:53:03"
[26] "Built: R 2.15.1; x86_64-pc-mingw32; 2012-06-22 14:16:09 UTC; windows"
[27] "Archs: i386, x64"
R>
एक पूरे इस के लिए समर्पित पुस्तिका नहीं है ...
स्रोत
2012-09-27 17:13:31
समस्या यह है कि आप पूरी फ़ाइल को ''line = readLines (con)' में पढ़ते हैं) और फिर आप लूप के अंदर फ़ाइल को पढ़ना जारी रखते हैं; बिंदु पर, पढ़ने के लिए कुछ भी नहीं बचा है। –
यदि आप [वर्तमान में स्वीकृत उत्तर] (http://stackoverflow.com/a/12627356/1067114) की तुलना में एक (शायद बड़ी) फ़ाइल से एक समय में केवल एक पंक्ति लोड करने का तरीका ढूंढ रहे हैं, तो यह आपके समाधान को हल नहीं कर रहा है मुसीबत। यदि, इसके बजाय, आप फ़ाइल लाइन की सामग्री को लाइन से संसाधित करना चाहते हैं, भले ही आप इसे कैसे लोड करते हैं, शायद सवाल बेहतर तैयार किया जाना चाहिए। –