silly question about writing own function
3
0
Entering edit mode
@james-anderson-1641
Last seen 10.2 years ago
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/bioconductor/attachments/20070228/ 6854cb66/attachment.pl
• 1.1k views
ADD COMMENT
0
Entering edit mode
@sean-davis-490
Last seen 3 months ago
United States
On Wednesday 28 February 2007 11:38, James Anderson wrote: > Hi, > > I have a rather simple question for writing my own function. Suppose I > wrote a script "A" which called function B written by myself. Seems that I > need to write the function B within the script A. Is there anyway to write > B as a separate script (so that we have A and B two scripts within the same > directory). I tried to do this but it seems that I must write function B > within script A for them to work. I am very familiar with matlab, but new > to R. I wonder how to do this, thanks. R will not load scripts directly (it doesn't have a concept of the path, like matlab). You simply need to source('B.R') before calling it in A. See the help for source(). Sean
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 3 hours ago
United States
James Anderson wrote: > Hi, > > I have a rather simple question for writing my own function. Suppose > I wrote a script "A" which called function B written by myself. Seems > that I need to write the function B within the script A. Is there > anyway to write B as a separate script (so that we have A and B two > scripts within the same directory). I tried to do this but it seems > that I must write function B within script A for them to work. I am > very familiar with matlab, but new to R. I wonder how to do this, > thanks. Works for me: > a <- function(x) x^2 > b <- function(y) a(y) - y > b(2) [1] 2 > b(3) [1] 6 If both functions are in your workspace (the .GlobalEnv) then b should be able to find a. When the functions are part of a package things get a bit more complicated, especially if the package has a namespace. What were you doing that didn't work? Best, Jim > > James > > > --------------------------------- Be a PS3 game guru. > > [[alternative HTML version deleted]] > > _______________________________________________ Bioconductor mailing > list Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor Search the > archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor -- James W. MacDonald, M.S. Biostatistician Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623 ********************************************************** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues.
ADD COMMENT
0
Entering edit mode
Ido M. Tamir ▴ 320
@ido-m-tamir-1268
Last seen 10.2 years ago
On Wednesday 28 February 2007 17:38, James Anderson wrote: > Hi, > > I have a rather simple question for writing my own function. Suppose I > wrote a script "A" which called function B written by myself. Seems that I > need to write the function B within the script A. Is there anyway to write > B as a separate script (so that we have A and B two scripts within the same > directory). I tried to do this but it seems that I must write function B > within script A for them to work. I am very familiar with matlab, but new > to R. I wonder how to do this, thanks. ?source in "A.R": source("B.R") where "B.R" is your script file in the same directory as "A.R". HTH ido > James > > --------------------------------- > Be a PS3 game guru. Please send me one.
ADD COMMENT

Login before adding your answer.

Traffic: 851 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6