0

I want to one parameter in one R script in another R script. For example in the first file for reading data:

wb <- loadWorkbook("adress")
dat <-readWorksheet(wb, sheet=getSheets(wb)[1], startRow=strow, endRow=endrow, startCol=spalte, endCol=spalte,header=FALSE)
datalist<-dat[,1]
while(n<=length(datalist))
{
  m<-strsplit(datalist[n],split=",")
  m<-sapply(m,as.numeric)
  m<-c(m)

  input<-m
  # here I want to set input to another file
  run1 <- parse("~/second.R")

  n<-n+30
}

In the second.R I have a parameter which name is input

but this code doesnt run second.R. What should I do to solve this problem?

Update

the second.R is:

wbdb <- loadWorkbook("C:\\Adress\\Muster.xls")
datdb <-readWorksheet(wbdb, sheet=getSheets(wb)[1], startRow=1, endRow=35, startCol=1, endCol=2,header=FALSE)
datalistdb<-datdb[,1]

ke<-length(input)
i<-1
near<-1000
position<-0
while(i < 35)
{ 
  m<-strsplit(datalistdb[i],split=",")
  m<-sapply(m,as.numeric)
  m<-c(m)
  alignment<-dtw(input,m)


  if(alignment$distance < near)
  {
    near<-alignment$distance
    position<-i
  }
  i<-i+1
}
position
datdb[position,2]
3
  • What is the exact content of second.R? Do you want to run second.R with the input variable set to m and then get the result to run1? Commented Jan 8, 2014 at 17:12
  • 2
    Isn't this the sort of thing god created functions for? Commented Jan 8, 2014 at 17:41
  • Yes, you are right, but I want to test it in this way :) Commented Jan 8, 2014 at 17:46

2 Answers 2

1

You have to use:

run1 <- source("~/second.R")
Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your answer, now I am seeing something as an output, but not what I am expecting: $value [1] 33 $visible [1] TRUE
check your code, I did't get what you're trying do. Also, you can always open other question.
1

You need to call eval with second.R:

run1 <- eval(parse("~/second.R"))

6 Comments

thank you for your answer, but it doesn't work. I want to run second.R an Have a resualt in While loop for each loop
again, what is the exact content of second.R?
I have updated my post, I want to have position and datdb[position,2] as result in First.R
You can only have one return value, so to speak. So change the end of second.R to c(position, datdb[position,2]), and then access them from first.R as run1[1] and run1[2]
If I do that I get this error: Error: IllegalArgumentException (Java): Sheet index (-1) is out of range (0..2)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.