[R] unable to carry through object in a nested function

arun smartpink111 at yahoo.com
Thu Jan 23 05:48:22 CET 2014


Hi,
Try this:
GetPropPlot<- function (PrePropData, direction, SSThreshold, cell, stim) {
       if (direction== ">") {
        PropData<-ddply(PrePropData,.(SUBJECT, STIM, CELL, SIGNAL, DAY), here(summarise),
            PROP=FindGreaterThanProportion(SIMSCORE, SSThreshold))
        }
    PlotSubset <- subset(PropData, STIM==stim & CELL == cell)
    FinalPropPlot<-ggplot(data=PlotSubset, aes(x=DAY, y=PROP)) +
        geom_line() +
        geom_point() +
        facet_grid(SIGNAL~SUBJECT)
    return(FinalPropPlot)
    }


GetPropPlot(PrePropData, direction=">", SSThreshold=3, "CD4", "No")
A.K.


On Wednesday, January 22, 2014 10:51 PM, "Chen, George" <George.Chen at roswellpark.org> wrote:
Hi,
This is a resend of a previous message reproduced below but with sample data to run.
Thanks.
George Chen



Hi There,
I am having trouble carrying through an object listed in the outer function into the inner function of a nested pair.

--------sample data below ---------
library(plyr)

SUBJECT<-c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
STIM<-c("No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No")
CELL<-c("CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4","CD4")
SIGNAL<-c("ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC")
DAY<-c(7,7,7,7,7,7,7,7,7,7,1,1,1,1,1,1,1,1,1,1)
SIMSCORE<-c(2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,5)
PrePropData<-data.frame(SUBJECT, STIM, CELL, SIGNAL, DAY, SIMSCORE)
________________________________


This is my code:

FindGreaterThanProportion<- function (y, SSThreshold) {
    DenomCells<-length(y)
    NumerCells<-subset(y,y>SSThreshold)
    PropCells<-length(NumerCells)/DenomCells
    return (PropCells)
    }


GetPropPlot<- function (PrePropData, direction, SSThreshold, cell, stim) {
    # Split up the dataframe with ddply and apply the function
    print(direction)
    print (SSThreshold)

    if (direction==">") {
        PropData<-ddply(PrePropData,.(SUBJECT, STIM, CELL, SIGNAL, DAY), summarise,
            PROP=FindGreaterThanProportion(SIMSCORE, SSThreshold))
        }

    PlotSubset <- subset(PropData, PropData$STIM==stim & PropData$CELL == cell)
    PropPlot<-ggplot(data=PlotSubset, aes(x=DAY, y=PROP)) +
        geom_line() +
        geom_point() +
        facet_grid(SIGNAL~SUBJECT)
    return(FinalPropPlot)
    }

GetPropPlot(PrePropData, direction=">", SSThreshold=3, "CD4", "No")

When I run the code, I get this error:
[1] ">"
[1] 3

Error in subset.default(y, y > SSThreshold) :
  object 'SSThreshold' not found

It seems as if SSThreshold is not being passed into FindGreaterThanProportion.

Any help would be appreciated to determine what I am doing incorrectly.
Thanks in advance.

George Chen



This email message may contain legally privileged and/or confidential information.  If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited.  If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you.
______________________________________________
R-help at 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.





More information about the R-help mailing list