[R] how to find the table in R studio

Avi Gross @v|gro@@ @end|ng |rom ver|zon@net
Thu Jan 13 04:17:55 CET 2022

The table you are looking for indeed does not any longer exists. Kai.
Anything created within a function generally disappears as soon as it exits as the only pointer to it goes away and garbage collection can eventuially reuse the space.
The code you wrote should end with:

MyNamedVariable <- f1(iris, Species)
It will then have a pointer to it and will show up as that name in the RSTUDIO window for Environment when it is the selected function of the upper right. 
By just writing this:

f1(iris, Species)

What you effectively did at the console level is this becue of automatic printing:

print(f1(iris, Species))

As soon as the printing is done, nothing is pointing at the memory location in the current environment or any environment.
There are, of course, ways for your f1() function to create a variable and save it in another environment such as global or parent under a designated name, but the easiest thing to do is to save teh result as shown as the return value of the function. Again, note, that if the place the function is called from is another function, any variables within it will disappear again when it exists, ...
Not suggesting you use it, but there is an assignment operator that assigns outside the immediate function using <<-
But back to your code, tell us more about the function view() you call several times in f1() and I assume you used it in debugging and it is not to be kept. On my machine the normal function is capitalized as View() so I am guessing you are getting the tidyverse version with view() in all lower case. It does return the object viewed and as that is the last line, it will return the object from the function. But probably not the best or most obvious way to return something as using the more standard View() function returns NULL.

-----Original Message-----
From: Kai Yang via R-help <r-help using r-project.org>
To: R-help Mailing List <r-help using r-project.org>
Sent: Wed, Jan 12, 2022 3:07 pm
Subject: [R] how to find the table in R studio

Hi all,
I created a function in R. It will be generate a table "temp". I can view it in R studio, but I cannot find it on the top right window in R studio. Can someone tell me how to find it in there? Same thing for f_table. 
Thank you,

f1 <- function(indata , subgrp1){
  subgrp1 <- enquo(subgrp1)
  indata0 <- indata
  temp    <- indata0 %>% select(!!subgrp1) %>% arrange(!!subgrp1) %>% 
    group_by(!!subgrp1) %>%
    mutate(numbering =row_number(), max=max(numbering))
  f_table <- table(temp$Species)

f1(iris, Species)

    [[alternative HTML version deleted]]

R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
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]]

More information about the R-help mailing list