This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
server <- function(input, output) { | |
output$input_value <- renderPrint({ | |
cat(input$slide) # cat() is an alternative to print(), see: ?cat() | |
}) ## I'm only using it here to hide the index that | |
## would be otherwise outputted. For example: | |
## > print(2) | |
## [1] 2 | |
## > cat(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r_length <- function(x) { | |
out <- 0L | |
for (i in x) { | |
out <- out + 1L | |
} | |
out | |
} | |
r_vector <- 1:20 | |
r_length(r_vector) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def py_length(x): | |
out = 0 | |
for i in x: | |
out += 1 | |
return out | |
py_generator = range(1, 21) | |
result = py_length(py_generator) | |
print(result) | |
#> 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Rcpp.h> | |
using namespace Rcpp; | |
// [[Rcpp::export]] | |
int cpp_length(NumericVector x) { | |
int out = 0; | |
for (NumericVector::iterator iter = x.begin(); iter != x.end(); iter++) { | |
out++; | |
} | |
return out; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r_vector <- 1:20 | |
length(r_vector) | |
#> [1] 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
py_generator = range(1, 21) | |
result = len(py_generator) | |
print(result) | |
#> 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Rcpp.h> | |
using namespace Rcpp; | |
// [[Rcpp::export]] | |
int cpp_size(NumericVector x) { | |
return x.size(); | |
} | |
/*** R | |
cpp_size(1:20) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> // std::cout, std::endl | |
#include <vector> // std::vector | |
using std::cout; | |
using std::endl; | |
using std::vector; | |
int length(vector<double> &x) { | |
int out = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
numpy_array = np.array(range(1, 21)) | |
result = np.size(numpy_array) | |
print(result) | |
#> 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> // std::cout, std::endl | |
#include <vector> // std::vector | |
using std::cout; | |
using std::endl; | |
using std::vector; | |
int main() { | |
vector<double> v{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; | |
OlderNewer