[R] loading data from a specified directory

Ott Toomet siim at obs.ee
Mon Sep 9 09:55:07 CEST 2002


On Mon, 9 Sep 2002, Sam McClatchie wrote:
  |
  |I have some text files in a certain directory and want to process them 
  |sequentially. So I want to pass the filename identifier into a function 
  |and loop through the processing of each file in turn.I've called the 
  |file identifier f in this code segment:
  |
  |image.dvm <- function (horiz.slice.int=2, ping.int=3,
  |                        start.h=3, start.min=4,
  |                        max.z=800, f=350:372)
  |{

  |   for (i in 1:length(f))
  |       paste("t.",f[1], sep="") 
  |<-read.table(paste("/home/smc/manuscripts/mesopelagic_fish/biomass_spectrum/we0000",f[1],sep=""), 
  |header=F)

  |Error in image.dvm() : Target of assignment expands to non-language object
  | >
  |
  |I guess I'm doing something illegal with the paste command?
  |
  |   paste("t.",f[1], sep="") <- read.table....

Hi,

You must not use paste() in this context.  Paste cannot be used for
assigning variable name, you must use assign() instead.  Write something
like

assign(paste("t.", f[1], sep=""), read.table(...))

but check it.

Cheers,

Ott

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list