関数オプションの部分的マッチングを敢えて防ぐ工夫
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
*関数オプションの部分的マッチングを敢えて防ぐ工夫
R の関数のオプションは部分的マッチングの採用によりオプシ...
注意:そのうち r-help アーカイブへの参照に変更します。
On Fri, 2004-02-27 at 07:10, "Jens Oehlschl?gel" wrote:
>> Dear R-experts,
>>
>> I just tracked down a nasty bug in a dynamically param...
>> wrong argument matching. As we get more and more compl...
>> top of R (like bioconductor) partial matching gets mor...
>> would like to deactivate partial matching in R (partia...
>> well as partial matching of list elements), e.g. using...
>> variable. If this is currently not possible this would...
>> wishlist topic.
As a temporary solution for the argument matching issue, ...
modify the code for match.arg() and add a T/F 'exact' arg...
using either match() or pmatch(), the latter of which is ...
default. match.arg() is a fairly short function.
my.match.arg <- function (arg, choices, exact = FALSE)
{
if (missing(choices)) {
formal.args <- formals(sys.function(sys.parent()))
choices <- eval(formal.args[[deparse(substitute(a...
}
if (all(arg == choices))
return(choices[1])
# HERE IS THE MODIFIED CODE
if (exact)
i <- match(arg, choices)
else
i <- pmatch(arg, choices)
# END MODIFIED CODE
if (is.na(i))
stop(paste("ARG should be one of",
paste(choices, collapse = ", "), sep = " "))
if (length(i) > 1)
stop("there is more than one match in match.arg")
choices[i]
}
I did not add any additional error checking code here or ...
handle non-matches, since that maybe unique to your appli...
I am not sure what you are using for list element matchin...
but a similar approach can feasibly be taken there, keepi...
charmatch() is a .Internal.
In terms of global variables, you can always add one to y...
(ie. using .Rprofile). In that case, you could use the fo...
place of the four lines above, after setting options(exac...
value (ie. options(exact = TRUE) ):
if (options()$exact)
i <- match(arg, choices)
else
i <- pmatch(arg, choices)
You would of course need to ensure that options()$exact i...
upon the addition of non-base packages and then leave off...
argument as I have the function defined above.
I hope that this helps, keeping in mind I am only on my f...
coffee so far this morning...
Marc Schwartz
終了行:
*関数オプションの部分的マッチングを敢えて防ぐ工夫
R の関数のオプションは部分的マッチングの採用によりオプシ...
注意:そのうち r-help アーカイブへの参照に変更します。
On Fri, 2004-02-27 at 07:10, "Jens Oehlschl?gel" wrote:
>> Dear R-experts,
>>
>> I just tracked down a nasty bug in a dynamically param...
>> wrong argument matching. As we get more and more compl...
>> top of R (like bioconductor) partial matching gets mor...
>> would like to deactivate partial matching in R (partia...
>> well as partial matching of list elements), e.g. using...
>> variable. If this is currently not possible this would...
>> wishlist topic.
As a temporary solution for the argument matching issue, ...
modify the code for match.arg() and add a T/F 'exact' arg...
using either match() or pmatch(), the latter of which is ...
default. match.arg() is a fairly short function.
my.match.arg <- function (arg, choices, exact = FALSE)
{
if (missing(choices)) {
formal.args <- formals(sys.function(sys.parent()))
choices <- eval(formal.args[[deparse(substitute(a...
}
if (all(arg == choices))
return(choices[1])
# HERE IS THE MODIFIED CODE
if (exact)
i <- match(arg, choices)
else
i <- pmatch(arg, choices)
# END MODIFIED CODE
if (is.na(i))
stop(paste("ARG should be one of",
paste(choices, collapse = ", "), sep = " "))
if (length(i) > 1)
stop("there is more than one match in match.arg")
choices[i]
}
I did not add any additional error checking code here or ...
handle non-matches, since that maybe unique to your appli...
I am not sure what you are using for list element matchin...
but a similar approach can feasibly be taken there, keepi...
charmatch() is a .Internal.
In terms of global variables, you can always add one to y...
(ie. using .Rprofile). In that case, you could use the fo...
place of the four lines above, after setting options(exac...
value (ie. options(exact = TRUE) ):
if (options()$exact)
i <- match(arg, choices)
else
i <- pmatch(arg, choices)
You would of course need to ensure that options()$exact i...
upon the addition of non-base packages and then leave off...
argument as I have the function defined above.
I hope that this helps, keeping in mind I am only on my f...
coffee so far this morning...
Marc Schwartz
ページ名: