R编程功能没有()(R programming function without ())
所以,我有以下非常简单的map.r文件。
我正在尝试让用户在交互模式下键入“click”,然后使用该功能。
由于它是一个函数,用户必须键入“click()”我如何才能使它们只需要单词(没有括号),然后让该函数对img做一些事情。
所以用户输入:
mydist( “image.pnm”)
点击
//然后单击函数会执行它应该执行的操作
mydist <- function(mapfile) { img <- read.pnm(mapfile) plot(img) } click <- function() { //Prompt user to click on img }
So, I Have the following very simple map.r file.
I'm trying to have the user type "click" in interactive mode and then have the function .
Since it's a function, the user has to type "click()" how can I make it so that they only have to the word (w/o parentheses), and then have that function do something with the img.
So the user types:
mydist("image.pnm")
click
//And then the function click does what it's supposed to
mydist <- function(mapfile) { img <- read.pnm(mapfile) plot(img) } click <- function() { //Prompt user to click on img }
原文:https://stackoverflow.com/questions/8130469
最满意答案
如果
String
的长度(至少)为1,则可以执行以下操作:String text = letter.getText(); // get the value of the JTextField char ch = text.charAt(0); // get the first letter as char
或者在一个声明中
char ch = letter.getText().charAt(0);
要么
char ch = letter.getText().toCharArray()[0];
If the length of the
String
is (at least) one, you can do this:String text = letter.getText(); // get the value of the JTextField char ch = text.charAt(0); // get the first letter as char
or in one statement, either
char ch = letter.getText().charAt(0);
or
char ch = letter.getText().toCharArray()[0];
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
这样的事情? #define STRLEN (64) char greeting[STRLEN]; strncpy(greeting,chrptr,STRLEN); if (strlen(chrptr) > (STRLEN-1)) greeting[(STRLEN-1)] = 0; something like this? #define STRLEN (64) char greeting[STRLEN]; strncpy(greeting,chrptr,STRLEN); if (strle ...
-
你想要c_str() 。 You want c_str().
-
如何将JTextfield的输入从字符串转换为char?(How do you convert the input from a JTextfield from a string to a char?)[2022-06-17]
如果String的长度(至少)为1,则可以执行以下操作: String text = letter.getText(); // get the value of the JTextField char ch = text.charAt(0); // get the first letter as char 或者在一个声明中 char ch = letter.getText().charAt(0); 要么 char ch = letter.getText().toCharArray()[0]; ... -
如何将JTextField输入转换为int以进行验证?(How can I convert JTextField input into int for validation?)[2023-05-05]
在解析之前,您可以尝试检查 if(contactnumber.trim().length() == 0) { } 此外,您可能希望使用long,因为int将无法存储10位数的联系号码。 Before parsing you may try to check if(contactnumber.trim().length() == 0) { } Also you may want to use long as int won't be able to store 10 digit contact numbe ... -
JTextField输入和输出(JTextField input and output)[2023-07-29]
欢迎来到可变字体,分辨率和DPI的精彩世界,它在屏幕上的样子永远不会与任何一个人相提并论(好吧,这是夸张的,但感觉就像:P) 在这个世界里,布局经理是你的朋友。 他们将为您节省许多,许多,数小时的挫折和折磨。 我建议你仔细阅读; 使用布局管理器 布局管理器的可视指南 这是我对你要做的事情的看法...... public class TestConvertDistance { public static void main(String[] args) { new TestConve ... -
显然txtMonth是一个JTexfield,但Double.parseDouble方法接收一个String。 在这里检查方法的javadoc。 尝试使用: double Amount = Double.parseDouble(txtMonth.getText()); 此外,如果文本无法转换为double,则此方法将抛出NumberFormatException。 Apparently txtMonth is a JTexfield, but the Double.parseDouble method r ...
-
从JTextfield获取输入(Get input from JTextfield)[2022-03-22]
当你真的想要使用模态JDialog时,你正在创建一个非模态JFrame。 将MyFrame2更改为模态JDialog,您的问题就解决了。 详细说明原因: 当您创建并显示非模态JFrame时,程序流会立即在显示JFrame的代码下方的调用代码中继续。 这意味着在用户没有机会向其添加信息之前,您将尝试从JTextField中提取数据。 另一方面,使用模态JDialog时,代码流会在显示JDialog时立即停止在调用代码中,并且在JDialog不再可见之前不会恢复。 因此,在用户处理对话框之前,不会调用显示对话框 ... -
尝试 NAME=t1["NAME"].ToString().Replace('"', ' ') 两个参数都应该是char https://msdn.microsoft.com/en-us/library/czx8s9ts(v=vs.110).aspx Try NAME=t1["NAME"].ToString().Replace('"', ' ') Both parameters should be char https://msdn.microsoft.com/en-us/library/czx8s9t ...