diff --git a/.gitignore b/.gitignore index 9b8474c..effb34c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ .Ruserdata *.o *.a -*~ \ No newline at end of file +*~ +*.dll \ No newline at end of file diff --git a/RBBGCMuso/NAMESPACE b/RBBGCMuso/NAMESPACE index 33413f3..099d7ae 100644 --- a/RBBGCMuso/NAMESPACE +++ b/RBBGCMuso/NAMESPACE @@ -54,6 +54,7 @@ importFrom(ggplot2,xlab) importFrom(ggplot2,ylab) importFrom(limSolve,xsample) importFrom(magrittr,'%<>%') +importFrom(rmarkdown,pandoc_version) importFrom(rmarkdown,render) importFrom(scales,percent) importFrom(tcltk,tk_choose.files) diff --git a/RBBGCMuso/R/parametersweep.R b/RBBGCMuso/R/parametersweep.R index a7777d3..398e89a 100644 --- a/RBBGCMuso/R/parametersweep.R +++ b/RBBGCMuso/R/parametersweep.R @@ -20,9 +20,9 @@ paramSweep <- function(inputDir="./", outVar="daily_gpp", htmlOutName = "paramsweep.html"){ - if(is.null(rmarkdown::pandoc_version())){ - stop("In order to use parameterSweep you have to have pandoc (1.12.3+) installed or run this function from Rstudio\n -You can download pandoc from here: 'https://pandoc.org/', or Rstudio from here: 'https://www.rstudio.com/'") + if(is.null(pandoc_version())){ + stop("In order to use parameterSweep you have to have\n pandoc (1.12.3+) installed or run this function from Rstudio\n +You can download pandoc from here: 'https://pandoc.org/',\n or Rstudio from here: 'https://www.rstudio.com/'") } currDir <- getwd() opSystem <- Sys.info()[[1]] diff --git a/RBBGCMuso/src/musoIO.cpp~ b/RBBGCMuso/src/musoIO.cpp~ deleted file mode 100644 index 7d9f916..0000000 --- a/RBBGCMuso/src/musoIO.cpp~ +++ /dev/null @@ -1,128 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -using namespace Rcpp; -using namespace std; -// [[Rcpp::plugins(cpp11)]] - -// [[Rcpp::export]] -IntegerVector getWritePositions(double a){ - //getWritePositions returns abstract rownumbers to rownumbers and other indexek - // getWritePositions(173.72) = c(173,7,3) // it supports up to 10 subvalues - IntegerVector outVec(3); // outVec is vector of rowIndex, colNumber, choosen Index - a = a * 100; - outVec[0] = (int)a / 100; - outVec[1] = ((int)a /10) % 10 + 1; - outVec[2] = (int)a % 10; - - return outVec; -} - -IntegerMatrix getPositions(NumericVector v){ - - int numVari = v.size(); - IntegerMatrix indexek(numVari,3); - IntegerVector positions(3); - for(int i = 0; i < numVari; ++i){ - positions = getWritePositions(v[i]); - indexek(i,_) = positions; - } - return indexek; -} - - -void goNextLine(std::ifstream& fin){ - char c='a'; - while((c!='\n')&&(fin.get(c))){} -} - -#define NEXT goNextLine(fin) -int fileChanger(std::string inFile, std::string outFile, IntegerVector linum, NumericVector num, IntegerVector colnum, IntegerVector colindex){ - std::ifstream fin(inFile); - if (!fin.is_open()) { - stop("Cannot open " + inFile + " for read"); - } - std::ofstream fot(outFile); - - if (!fot.is_open()) { - stop("Cannot open " + outFile + " for read"); - } - string tempString; - - int counter = 1; - int counterV = 0; - while (!fin.eof()) { - - - if(counter == linum[counterV]){ - if(colnum[counterV]==0){ - fot << num[counterV] << "\n"; - NEXT; - } else { - double * elements; - elements = new double [colnum[counterV]]; - if(linum[counterV]!=linum[counterV+1]){ - for(int i=0;i> elements[i]; - if(i==colindex[counterV]){ - elements[i]=num[counterV]; - } - fot << elements[i] << '\t'; - } - } else { - int k=0; - for(int i=0;i> elements[i]; - if(i==colindex[counterV + k]){ - elements[i]=num[counterV + k]; - if(linum[counterV +k]==linum[counterV + k + 1]){ - ++k; - } - } - fot << elements[i] << '\t'; - - } - counterV = counterV + k; - } - - fot << "\n"; - delete [] elements; - NEXT; - } - ++counterV; - } else { - getline(fin,tempString); - fot << tempString << "\n"; - } - ++counter; - } - fin.close(); - fot.close(); - return 0; -} - -//' changeMusoC -//' -//' This function is fastly randomize values based on min and max values -//' @importFrom Rcpp evalCpp -//' @useDynLib RBBGCMuso -//' @param inFile is the big matrix -//' @param outFile is the small matrix -//' @export -// [[Rcpp::export]] -void changeMusoC(std::string inFile, std::string outFile, NumericMatrix inMat){ - int numChanges = inMat.nrow(); - IntegerMatrix indexes(numChanges,3); - indexes = getPositions(inMat(_,0)); - fileChanger(inFile,outFile,indexes(_,0),inMat(_,1),indexes(_,1),indexes(_,2)); -} diff --git a/RBBGCMuso/src/musoRandomizer.cpp~ b/RBBGCMuso/src/musoRandomizer.cpp~ deleted file mode 100644 index 12190a1..0000000 --- a/RBBGCMuso/src/musoRandomizer.cpp~ +++ /dev/null @@ -1,167 +0,0 @@ -#include -#include -#include -#include -#include -#include - - -using namespace Rcpp; -using namespace std; -// [[Rcpp::plugins(cpp11)]] - - - -NumericMatrix randTypeZero(NumericMatrix m){ - /* - A typical matrix like m: - - | INDEX | DEPENDENCE | MIN | MAX | - |-------+------------+------+------| - | 21 | 0 | 0 | 364 | - | 57 | 0 | bkla | asdf | - - This randomization type is the easiest, - the function produces a matrix which first - column contains the indexes, and the second contains - random numbers, which was drawn from uniform distribution - with the corresponding min and max parameters, specified - by the matrix m. - - */ - int n=m.nrow()-1; - NumericMatrix M(n+1,2); - M(_,0)=m(_,0); - for(int i=0;i<=n;++i){ - double min=m(i,2); - double max=m(i,3); - M(i,1)=runif(1,min,max)[0]; - } - return M; -} - -// [[Rcpp::export]] -NumericMatrix randTypeOne(NumericMatrix m){ - /* - The stucture of matrix m here is the same - as in randTypeZero. - - - - */ - - - NumericVector dependence=m(_,2); - int n=m.nrow()-1; - NumericMatrix M(n+1,2); - M(_,0)=m(_,0); - M(0,1)=runif(1,m(0,2),m(0,3))[0]; - for(int i=1;i<=n;++i){ - int dep=m(i,1)-1; - double min=max(M(dep,1),m(i,2)); - double max=m(i,3); - M(i,1)=runif(1,min,max)[0]; - } - return M; -} - - - -IntegerVector orderDec(NumericVector v){ - Function f("order"); - return f(v,_["decreasing"]=1); -} - -NumericMatrix randTypeTwo(NumericMatrix m){ - int n=m.nrow()-1; - int N=n-1; - NumericMatrix mv=m(Range(0,(n-1)),_); - NumericVector dependence=m(_,2); - NumericMatrix M(n+1,2); - M(_,0)=m(_,0); - IntegerVector indexes=orderDec(mv(_,2)); - NumericVector sorban=mv(_,2); - sorban.sort(true); - NumericVector sor=cumsum(sorban); - sor.sort(true); - for(int i=0;i<=N;++i){ - if(i!=N){ - mv((indexes[i]-1),3)-= sor[i+1]; - } - } - - double rollingNumber=0; - - for(int i=0;i<=N;++i){ - double minimum=mv((indexes[i]-1),2); - double maximum=mv((indexes[i]-1),3)-rollingNumber; - M(i,1)=runif(1,minimum,maximum)[0]; - rollingNumber+=M(i,1); - // cout << "minimum:\t" << minimum << endl; - // cout << "maximum:\t" << maximum << endl; - // cout << "indexes:\t" << indexes[i] << endl; - // cout << "rollingNumber:\t" << rollingNumber << endl; - // cout << "choosen:\t" << M(i,1) <