Displaying 20 results from an estimated 30000 matches similar to: "getting multiple argument names"
2005 Feb 08
5
How to get variable names in a function?
Hello,
applying a function to a list of variables I face the following problem:
Let's say I want to compute tables for several variables. I could write a
command for every single table, like
bravo<-c(1,1,2,3,5,5,5,);charly<-c(7,7,4,4,2,1)
table(bravo); table(charly)
> table(bravo); table(charly)
bravo
1 2 3 5
2 1 1 3
charly
1 2 4 7
1 1 2 2
The results are two tables with the
2005 Feb 17
5
Again: Variable names in functions
Hello,
still I have difficulties with variable names in functions. I know the
famous example form help for deparse/substitute but I will give a simpler
one to explain my problem.
I know from Reid Huntsinger (Tue, 8 Feb 2005 12:39:32 -0500) that:
"Semantically, R is pass-by-value, so you don't really have the names, just
the values. In implementation, though, R *does* pass names, in part
2012 Mar 24
3
argument names inside a function?
Is there a way I can get the names of the arguments passed to a
function from within a function?
2003 Feb 17
2
returning argument names
Dear r-list folks,
I have a problem which has been bugging me for a while now and I was hoping
someone out there might be able to help.
If I have a user-defined function with an indeterminate number of
arguments, using the well-known "..." construct, how can I get the
function to return the names of the items which were the arguments of the
function as part of the function's
2005 Feb 10
2
rewrite of scatter.smooth to handle NAs
I rewrote scatter.smooth to handle missing values, but I have a question
about a move I had to make. Here's the code:
Mscatter.smooth<-function (x, y, span = 2/3, degree = 1, family =
c("symmetric",
"gaussian"), xlab = deparse(substitute(x)), ylab =
deparse(substitute(y)),
ylim = range(y, prediction$y), evaluation = 50, ...)
{
if (inherits(x,
2010 May 25
1
using the name of an argument in a function
Hi all,
In a function, I need to get the name of a variable that has been used to
call the function.
For example, I want:
--- 8< ------
toto <- 3
fun <- function(y){
nameOfY <-deparse(substitute(y))
cat("name is ",nameOfY)
}
fun(toto)
# [1] name is toto
--- 8< ----
But deparse(substitute(y)) does not work all the time, especially when we
use generic function.
2007 Jun 01
2
Getting names of objects passed with "..."
Is there a tidy way to get the names of objects passed to a function via the
"..." argument?
rbind/cbind does what I want:
test.func1 <- function(...) {
nms <- rownames(rbind(..., deparse.level=1))
print(nms)
}
x <- "some stuff"
second <- "more stuff"
test.func1(first=x, second)
[1] "first" "second"
The usual
2018 Feb 20
0
deparseDots to get names of all arguments?
On 21/02/18 11:36, Spencer Graves wrote:
> Hi, All:
>
>
> ????? How can I get the names of all the arguments in dots(...)?
>
>
> ????? I'm able to get the name of the first argument but not the second:
>
>
>
> deparseDots <- function(...){
> ? deparse(substitute(...))
> }
> a <- 1
> b <- 2
> deparseDots(a, b)
> [1]
2006 Jul 27
2
How to get the name of the first argument in an assignment function?
Dear All!
If I pass an object to an assignment function I cannot get it's name by
deparse(substitute(argument)), but I get *tmp* and I found no way to get
the original name, in the example below it should be "va1".
Is there a way?
Thanks,
Heinz
## example
'fu1<-' <- function(var, value) {
print(c(name.of.var=deparse(substitute(var))))}
fu1(va1) <- 3
name.of.var
2004 Sep 20
2
Getting the real names of variables within functions
Greetings.
These days I find myself writing a lot of functions to handle routine
things. One of these is a function to create a scatterplot of
variables and draw a lowessed line so I can get some idea if there's
any relationship between them.
lowessed.plot <- function(x, y)
{ plot(x, y)
lines(lowess(x, y))
}
However, there's a slight problem: the plot axes come out labeled
2018 Feb 20
5
deparseDots to get names of all arguments?
Hi, All:
????? How can I get the names of all the arguments in dots(...)?
????? I'm able to get the name of the first argument but not the second:
deparseDots <- function(...){
? deparse(substitute(...))
}
a <- 1
b <- 2
deparseDots(a, b)
[1] "a"
????? I'd like to get c('a', 'b').
????? Thanks,
????? Spencer Graves
> sessionInfo()
R
2018 Feb 21
1
deparseDots to get names of all arguments?
On 20/02/2018 5:47 PM, Rolf Turner wrote:
> On 21/02/18 11:36, Spencer Graves wrote:
>> Hi, All:
>>
>>
>> ????? How can I get the names of all the arguments in dots(...)?
>>
>>
>> ????? I'm able to get the name of the first argument but not the second:
>>
>>
>>
>> deparseDots <- function(...){
>> ?
2005 Jul 19
2
using argument names (of indeterminate number) within a function
Although I tried to find an answer in the manuals and archives, I cannot
solve this (please excuse that my English and/or R programming skills
are not good enough to state my problem more clearly):
I want to write a function with an indeterminate (not pre-defined)
number of arguments and think that I should use the "..." construct and
the match.call() function. The goal is to write
2002 Apr 11
2
Obtaining names of ``...'' arguments.
This may be an FAQ, but a (perfunctory) search failed to turn it up.
Suppose I have a function foo(...){<something>} and I want to obtain,
inside foo, the names of items comprising the ``...''. E.g. if I
call
foo(melvin,clyde,irving)
I want to be able to loop through the ``...'' and successively obtain
the text strings "melvin", "clyde", and
2012 Feb 25
2
Finding name of variable supplied as function argument
Greetings All.
I want to do the following simple thing. I have defined
a function med3x3() such that, given vectors X,Y,
med3x3(X,Y) returns a 3x3 table where:
Row 1: X > median(X)
Row 2: X = median(X)
Row 3: X < median(X)
Col 1: Y < median(Y)
Col 2: Y = median(Y)
Col 3: Y > median(Y)
(with intersections of these conditions for the individual cells).
I can easily define fixed
2008 Apr 13
1
promptFunctions() to handle multiple names
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Hi all,
I wanted to set up my first (private) R-package and wondered
if there was a function to prompt() for multiple aliases in one Rd-file,
e.g. to create something like the normal distribution manual page
encompassing rnorm, dnorm,...
As I didn't find it, I modified prompt.default() and wrote a small function
to do this job, called
2009 Sep 24
1
how to make a function recognize the name of an object/vector given as argument
Dear guRus,
I'd like to learn how to make a function recognize the name of an
object/vector given as argument
If I have :
testFun <- function(x,y) plot(x,y, main=paste("plot
of",names(x),"and",names(y)) ) # this just a simple example ...
a1 <- 5:8
b1 <- 9:6
testFun(a1,b1)
# Returns the plot, but not the names of the objects/vectors given as
arguments,
# but
2007 Dec 09
1
Obtaining names of further arguments ('...')
Hi,
I would like to obtain the names of all objects that are provided as further
arguments ("...") in a function call. I have created a minimal example that
illustrates my wish (but isn't useful otherwise):
f1 <- function( ... ) return( deparse( substitute( ... ) ) )
x1 <- 1
x2 <- 2
x3 <- 3
f1( x1, x2, x3 )
[1] "x1"
However, I would like to obtain the
2007 Oct 25
3
Deparsing part of a list argument
Here's a simple example of the type of function I'm trying to write,
where the first argument is a list of functions:
myfun <- function(funlist, vec){
tmp <- lapply(funlist, function(x)do.call(x, args = list(vec)))
names(tmp) <- names(funlist)
tmp
}
> myfun(list("Summation" = sum, prod, "Absolute value" = abs), c(1, 4, 6, 7))
$Summation
[1]
2005 Jul 19
2
Obtaining argument name within a function
Dear all
How can I obtain the name of the argument passed in a function? Here is a
simplistic example of what I would like to obtain:
myfunction= function(name) {
print(paste("The parameter name was",unknownFunction(name))
}
myfunction(myobject)
[1] "The parameter name was myobject"
Thanks
Francisco