stephen sefick
2017-Feb-20 21:20 UTC
[R] Make sure a data frame has been "fun through" a function
Hello, I would like to add something to a data frame that is 1) invisible to the user, 2) has no side effects, and 3) I can test for in a following function. Is this possible? I am exploring classes and attributes and I have thought about using a list (but 1 and 2 not satisfied). Any help would be greatly appreciated. I did not provide a reproducible example because I see this as more of a R language question, but I will be happy to make a toy example if that would help. I appreciate all of the help. kindest regards, -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis "A big computer, a complex algorithm and a long time does not equal science." -Robert Gentleman [[alternative HTML version deleted]]
Ista Zahn
2017-Feb-20 23:25 UTC
[R] Make sure a data frame has been "fun through" a function
It depends on what you mean by 1). If you mean "won't annoy the user" then yes, e.g., add something to the class attribute. If 1) means "can't be discovered by the user" then no (at least not easily). Anything you can see they can see. Best, Ista On Feb 20, 2017 4:21 PM, "stephen sefick" <ssefick at gmail.com> wrote: Hello, I would like to add something to a data frame that is 1) invisible to the user, 2) has no side effects, and 3) I can test for in a following function. Is this possible? I am exploring classes and attributes and I have thought about using a list (but 1 and 2 not satisfied). Any help would be greatly appreciated. I did not provide a reproducible example because I see this as more of a R language question, but I will be happy to make a toy example if that would help. I appreciate all of the help. kindest regards, -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis "A big computer, a complex algorithm and a long time does not equal science." -Robert Gentleman [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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. [[alternative HTML version deleted]]
Bert Gunter
2017-Feb-20 23:53 UTC
[R] Make sure a data frame has been "fun through" a function
Yes. To elaborate a bit on Ista's reply: A) The only way I can imagine hiding info from a user would be to encrypt it. This could be done programmatically I think, but I would have to research it to figure out how. B) If all you want to do is prevent the info from being printed, just create e.g an S3 class of type "foo" that inherits from "data.frame" with your info as an attribute and provide a print.foo method that just prints the data frame without the attribute. Your function can access and use the attribute any way it likes. Cheers, Bert Bert On Feb 20, 2017 1:27 PM, "Ista Zahn" <istazahn at gmail.com> wrote: It depends on what you mean by 1). If you mean "won't annoy the user" then yes, e.g., add something to the class attribute. If 1) means "can't be discovered by the user" then no (at least not easily). Anything you can see they can see. Best, Ista On Feb 20, 2017 4:21 PM, "stephen sefick" <ssefick at gmail.com> wrote: Hello, I would like to add something to a data frame that is 1) invisible to the user, 2) has no side effects, and 3) I can test for in a following function. Is this possible? I am exploring classes and attributes and I have thought about using a list (but 1 and 2 not satisfied). Any help would be greatly appreciated. I did not provide a reproducible example because I see this as more of a R language question, but I will be happy to make a toy example if that would help. I appreciate all of the help. kindest regards, -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis "A big computer, a complex algorithm and a long time does not equal science." -Robert Gentleman [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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. [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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. [[alternative HTML version deleted]]
stephen sefick
2017-Feb-20 23:59 UTC
[R] Make sure a data frame has been "fun through" a function
Yes, I mean "won't annoy the user", will allow them to do anything they need to do with a dataframe (write to csv, etc.), but will allow me to test for in a down stream function of the analysis to stop the function and present an error. Adding something to the class attribute seems like the right thing to do. With my clarification do you think these seems like a sensible thing to do? Thank you for all of the help. kindest regards, Stephen On Mon, Feb 20, 2017 at 5:25 PM, Ista Zahn <istazahn at gmail.com> wrote:> It depends on what you mean by 1). If you mean "won't annoy the user" then > yes, e.g., add something to the class attribute. If 1) means "can't be > discovered by the user" then no (at least not easily). Anything you can see > they can see. > > Best, > Ista > > > On Feb 20, 2017 4:21 PM, "stephen sefick" <ssefick at gmail.com> wrote: > > Hello, > > I would like to add something to a data frame that is 1) invisible to the > user, 2) has no side effects, and 3) I can test for in a following > function. Is this possible? I am exploring classes and attributes and I > have thought about using a list (but 1 and 2 not satisfied). Any help would > be greatly appreciated. > > I did not provide a reproducible example because I see this as more of a R > language question, but I will be happy to make a toy example if that would > help. > > I appreciate all of the help. > > kindest regards, > > -- > Let's not spend our time and resources thinking about things that are so > little or so large that all they really do for us is puff us up and make us > feel like gods. We are mammals, and have not exhausted the annoying little > problems of being mammals. > > -K. Mullis > > "A big computer, a complex algorithm and a long time does not equal > science." > > -Robert Gentleman > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posti > ng-guide.html > and provide commented, minimal, self-contained, reproducible code. > > >-- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis "A big computer, a complex algorithm and a long time does not equal science." -Robert Gentleman [[alternative HTML version deleted]]
stephen sefick
2017-Feb-21 00:02 UTC
[R] Make sure a data frame has been "fun through" a function
Just as clarification, I don't want to hide anything from the user. I just want to add something that I can test for in downstream function. I appreciate all of the help. kindest regards, Stephen On Mon, Feb 20, 2017 at 5:53 PM, Bert Gunter <bgunter.4567 at gmail.com> wrote:> Yes. > > To elaborate a bit on Ista's reply: > > A) The only way I can imagine hiding info from a user would be to > encrypt it. This could be done programmatically I think, but I would have > to research it to figure out how. > > B) If all you want to do is prevent the info from being printed, just > create e.g an S3 class of type "foo" that inherits from "data.frame" with > your info as an attribute and provide a print.foo method that just prints > the data frame without the attribute. Your function can access and use the > attribute any way it likes. > > Cheers, > Bert > > > Bert > > On Feb 20, 2017 1:27 PM, "Ista Zahn" <istazahn at gmail.com> wrote: > > It depends on what you mean by 1). If you mean "won't annoy the user" then > yes, e.g., add something to the class attribute. If 1) means "can't be > discovered by the user" then no (at least not easily). Anything you can see > they can see. > > Best, > Ista > > > On Feb 20, 2017 4:21 PM, "stephen sefick" <ssefick at gmail.com> wrote: > > Hello, > > I would like to add something to a data frame that is 1) invisible to the > user, 2) has no side effects, and 3) I can test for in a following > function. Is this possible? I am exploring classes and attributes and I > have thought about using a list (but 1 and 2 not satisfied). Any help would > be greatly appreciated. > > I did not provide a reproducible example because I see this as more of a R > language question, but I will be happy to make a toy example if that would > help. > > I appreciate all of the help. > > kindest regards, > > -- > Let's not spend our time and resources thinking about things that are so > little or so large that all they really do for us is puff us up and make us > feel like gods. We are mammals, and have not exhausted the annoying little > problems of being mammals. > > -K. Mullis > > "A big computer, a complex algorithm and a long time does not equal > science." > > -Robert Gentleman > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posti > ng-guide.html > and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posti > ng-guide.html > and provide commented, minimal, self-contained, reproducible code. > > >-- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis "A big computer, a complex algorithm and a long time does not equal science." -Robert Gentleman [[alternative HTML version deleted]]
Charles C. Berry
2017-Feb-21 00:24 UTC
[R] Make sure a data frame has been "fun through" a function
On Mon, 20 Feb 2017, stephen sefick wrote:> Hello, > > I would like to add something to a data frame that is 1) invisible to the > user, 2) has no side effects, and 3) I can test for in a following > function. Is this possible? I am exploring classes and attributes and I > have thought about using a list (but 1 and 2 not satisfied). Any help would > be greatly appreciated. >Depends on exactly what you mean by `invisible' and `side effects'. You can do this (but I am not necessarily recommending this):> add.stuff <- function(x,...){+ class(x)<- c("more.stuff",class(x)) + attr(x,"stuff")<- list(...) + x}>And printing and model functions will be unaffected:> df <- data.frame(a=1:3,b=letters[1:3]) > df2 <- add.stuff(df,comment="wow", length="3 rows") > df2a b 1 1 a 2 2 b 3 3 c> attr(df2,"stuff")$comment [1] "wow" $length [1] "3 rows"> all.equal(lm(a~b,df),lm(a~b,df2)) # only call should differ[1] "Component ?call?: target, current do not match when deparsed">And if you need some generics to take account of the "stuff" attribute, you can write the methods to do that. --- Another solution is to put your data.framne in a package and then have other objects hold the 'stuff' stuff. Once your package is loaded or imported, the user will have access to the data in a way that might be said to be `invisible' in ordinary usage. --- But seriously, you should say *why* you want to do this. There are probably excellent solutions that do not involve directly altering the data.frame and may not involve putting together a package. HTH, Chuck
stephen sefick
2017-Feb-21 00:43 UTC
[R] Make sure a data frame has been "fun through" a function
Hello All, I am writing a package. I would like to encourage the user to look at the data to rectify errors with function A before utilizing function B to code these data as binary. I thought about solving this problem by adding a "flag" in the attributes that could be used downstream in B, and have a function that adds this "flag" if the user is convinced that everything is okay. This would allow the user to utilize their data as is, if error checking is not necessary. Maybe I am overthinking this. Thanks again. kindest regards, Stephen On Mon, Feb 20, 2017 at 6:24 PM, Charles C. Berry <ccberry at ucsd.edu> wrote:> On Mon, 20 Feb 2017, stephen sefick wrote: > > Hello, >> >> I would like to add something to a data frame that is 1) invisible to the >> user, 2) has no side effects, and 3) I can test for in a following >> function. Is this possible? I am exploring classes and attributes and I >> have thought about using a list (but 1 and 2 not satisfied). Any help >> would >> be greatly appreciated. >> >> > Depends on exactly what you mean by `invisible' and `side effects'. > > You can do this (but I am not necessarily recommending this): > > add.stuff <- function(x,...){ >> > + class(x)<- c("more.stuff",class(x)) > + attr(x,"stuff")<- list(...) > + x} > >> >> > And printing and model functions will be unaffected: > > df <- data.frame(a=1:3,b=letters[1:3]) >> df2 <- add.stuff(df,comment="wow", length="3 rows") >> df2 >> > a b > 1 1 a > 2 2 b > 3 3 c > >> attr(df2,"stuff") >> > $comment > [1] "wow" > > $length > [1] "3 rows" > > all.equal(lm(a~b,df),lm(a~b,df2)) # only call should differ >> > [1] "Component ?call?: target, current do not match when deparsed" > >> >> > And if you need some generics to take account of the "stuff" attribute, > you can write the methods to do that. > > --- > > Another solution is to put your data.framne in a package and then have > other objects hold the 'stuff' stuff. Once your package is loaded or > imported, the user will have access to the data in a way that might be said > to be `invisible' in ordinary usage. > > --- > > But seriously, you should say *why* you want to do this. There are > probably excellent solutions that do not involve directly altering the > data.frame and may not involve putting together a package. > > HTH, > > Chuck-- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis "A big computer, a complex algorithm and a long time does not equal science." -Robert Gentleman [[alternative HTML version deleted]]