You need to understand the difference between a variable and a value.

In your case that doesn't work, you are supplying a value, "trait.value".
but you have no file named "trait.value".

In the case that does work you are supplying a variable, trait.value, and
the value contained in that variable is the name of a file that does exist.

It is not quite correct to say that when using read.csv() you put quotation
marks outside the filename. What you do is supply read.csv() with the name
of a file, and that name can either be a character string, or a variable
whose value is a character string.

-Don

On 7/16/10 8:23 AM, "karena" <dr.jz...@gmail.com> wrote:

> 
> Following is a function that I wrote (It is working well). It's a simple one,
> nothing complicated. The only question that I have is a qutation mark issue,
> I guess.
> #############################################
> funcname <- function(trait.file){                                #line1
> setwd('/root/subroot')                 # line 2
> load('imge.RData')                                        # line3
> imge <- imge[,-c(3)]                         # line4
> imge <- imge[complete.cases(imge),]   # line5
> trait<- read.csv(trait.file)             # line6
> ngenes <- nrow(imge)     # line7
> nsnp <- nrow(trait)              #line 8
> for(i in 1:ngenes) {
>   for(j in 1:nsnp) {
> if(imge$d1[i]==trait$d1[j] & imge$d2[i]==trait$d2[j]) trait$imgene2[j] <-
> imge$Gene[i]
>       else trait$imgene2[j] <- NA
>    }
> }
>    return(trait)
> }
> 
> hypertension <- funcname("folder/hyper.csv")     # last line
> ######################################
> 
> So, as we all know, when using "read.csv", we need to use qutation mark out
> side the filename which we wanna read in. At first, for line 8, I wrote:
> read.csv("trait.file"), at last line, I wrote:
> funcname(folder/hyper.csv), but it did not work in this way. Unless I
> changed the code to the current one that I showed above, I couldn't get what
> I want.  
> So, to be straightforward, I will show the difference:
> 1) the code not working:
> read.csv("trait.file")       #line 8
> funcname(folder/hyper.csv)  #last line
> 
> 2) the code working:
> read.csv(trait.file)         # line 8
> funcname("folder/hyper.csv")   # last line
> 
> anyone can tell me why is the difference?
> 
> thank you,
> 
> karena
> 

-- 
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
925 423-1062

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to