Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.
kishorekumar
A minimal reproducible example consists of the following items:
a minimal dataset, necessary to reproduce the error
the minimal runnable code necessary to reproduce the error, which can be run on the given dataset.
the necessary information on the used packages, R version, and the system it is run on.
in the case of random processes, a seed (set by set.seed()) for reproducibility
Looking at the examples in the help files of the used functions is often helpful. In general, all the code given there fulfills the requirements of a minimal reproducible example: data is provided, minimal code is provided, and everything is runnable.
Producing a minimal dataset
For most cases, this can be easily done by just providing a vector/data frame with some values. Or you can use one of the built-in datasets, which are provided with most packages.
A comprehensive list of built-in datasets can be seen with the library(help = “datasets”). There is a short description of every dataset and more information can be obtained for example with?m cars where ‘mtcars’ is one of the datasets in the list. Other packages might contain additional datasets.
Making a vector is easy. Sometimes it is necessary to add some randomness to it, and there are a whole number of functions to make that. sample() can randomize a vector, or give a random vector with only a few values. a letter is a useful vector containing the alphabet. This can be used for making factors.
A few examples :
random values : x <- rnorm(10) for normal distribution, x <- runif(10) for uniform distribution, …
a permutation of some values : x <- sample(1:10) for vector 1:10 in random order.
a random factor : x <- sample(letters[1:4], 20, replace = TRUE)
For matrices, one can use matrix(), eg :
matrix(1:10, ncol = 2)
Making data frames can be done using data.frame(). One should pay attention to name the entries in the data frame, and to not make it overly complicated.
An example :
set.seed(1)
Data <- data.frame(
X = sample(1:10),
Y = sample(c("yes", "no"), 10, replace = TRUE)
)
For some questions, specific formats can be needed. For these, one can use any of the provided as.someType functions: as.factor, as. Date, as.xts, … These in combination with the vector and/or data frame tricks.
kishorekumar
== tests for reference equality (whether they are the same object).
.equals() tests for value equality (whether they are logically “equal”).
Objects.equals() checks for null before calling .equals() so you don’t have to (available as of JDK7, also available in Guava).
String.contentEquals() compares the content of the String with the content of any CharSequence (available since Java 1.5).
Consequently, if you want to test whether two strings have the same value you will probably want to use Objects.equals().
// These two have the same value
new String(“test”).equals(“test”) // –> true
// … but they are not the same object
new String(“test”) == “test” // –> false
// … neither are these
new String(“test”) == new String(“test”) // –> false
// … but these are because literals are interned by
// the compiler and thus refer to the same object
“test” == “test” // –> true
// … string literals are concatenated by the compiler
// and the results are interned.
“test” == “te” + “st” // –> true
// … but you should really just call Objects.equals()
Objects.equals(“test”, new String(“test”)) // –> true
Objects.equals(null, “test”) // –> false
Objects.equals(null, null) // –> true
You almost always want to use Objects.equals(). In the rare situation where you know you’re dealing with interned strings, you can use ==.
kishorekumar
The most perfect answer to this question is using Promise.
function ajax(method, url, params) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
resolve(this.responseText);
};
xhr.onerror = reject;
xhr.open(method, url);
xhr.send(params);
});
}
kishorekumar
This can be done to some extent by installing the font GNU Unifont, and then applying custom CSS rules, like so, for example, to highlight any input areas that have backspace characters in them
input
{
font-family: Unifont;
}
For my use case, I’m using a browser extension that lets me apply custom CSS rules by domain. When I want to debug something like this, I enable the CSS rules for that domain and can now see if a backspace character is present on the page. From my quick tests though, it doesn’t seem to show TAB characters or newline/carriage returns in any visible way.
kishorekumar
This means that you could use only empty() to determine if the variable is set, and in addition, it checks the variable against the following, 0,”, null.
Example:
$o = [];
@$var = ["",0,null,1,2,3,$foo,$o['myIndex']];
array_walk($var, function($v) {
echo (!isset($v) || $v == false) ? 'true ' : 'false';
echo ' ' . (empty($v) ? 'true' : 'false');
echo "\n";
});