There is a simple R function code.
fx <- function(x){
lst <- list(a = x+1, b = x*2, c = x+c(1:100))
return(lst)
}
In this code, I want to hide 'lst$c' element because the data is long. So, I tried below
fx <- function(x){
lst <- list(a = x+1, b = x*2, c = x+c(1:100))
return(lst[c(1,2)])
}
object <- fx(1)
object
and get
###
$a
[1]2
$b
[1]2
and
fx <- function(x){
lst <- list(a = x+1, b = x*2, c = x+c(1:100))
invisible(lst)
}
object <- fx(1)
object
###
$a
[1]2
$b
[1]2
$c
[1]2 3 4 5 ....101
but I don't wanna lose the 'lst$c' data when I assign this function to object like this.
object <- fx(2)
object
## No return 'lst$c'.
$a
[1]2
$b
[1]2
str(object)
## not include 'lst$c'
List of 2
$ a: num 2
$ b: num 2
So, I want...
object
###
$a
[1]2
$b
[1]2
str(object)
## still have lst$c data in the data structure
List of 3
$ a: num 2
$ b: num 2
$ c: num [1:100] 2 3 4 5 6 7 ...
How can I do this?