鉴于:
public class MyClass {
static {
// Access to args is needed here
}
public static void main(String[] args) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
我想在上面提到的静态块中访问args.
我知道静态块是在类加载(或初始化)时和静态main函数之前执行的,但仍然想知道是否可以访问它的args.
顺便说一句 - 我的最终目标是在配置log4j之前在运行时追加日志文件的名称(使用从传递给main的其中一个参数派生的系统属性变量).
我想从用户那里动态获取条件,所以我构建了一个闪亮的应用程序,可以从输入字段中获取它们。问题是as.formula不适用于带有逗号的字符向量(没有效果的话)。
码:
all_conditions =
"condition1 ~ 0,
condition2 ~ 1,
condition3 ~ 2"
my_dataset %>% group_by(id) %>%
summarise(FLAG = case_when(
as.formula(all_conditions) )
)
Run Code Online (Sandbox Code Playgroud)
我得到:
评估错误:: 2:100:意外的','
我尝试使用paste和转义逗号没有成功。