Here you can find the source of objectArrayToRVector(Object[] rValues)
Parameter | Description |
---|---|
rValues | the values whose Object#toString() values we will use to form the list |
public static String objectArrayToRVector(Object[] rValues)
//package com.java2s; /*/* ww w. j av a2 s. c om*/ * Copyright (c) 2009 The Jackson Laboratory * * This software was developed by Gary Churchill's Lab at The Jackson * Laboratory (see http://research.jax.org/faculty/churchill). * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software. If not, see <http://www.gnu.org/licenses/>. */ public class Main { private static final String R_VECTOR_START = "c("; private static final String R_VECTOR_END = ")"; private static final String R_VECTOR_ELEMENT_SEPERATOR = ", "; /** * Convert the given values to an R vector. Note that the given values * are not quoted. It is assumed that if they are already in "R" form and * so the {@link Object#toString()} value is used directly * @param rValues * the values whose {@link Object#toString()} values * we will use to form the list * @return * the string that can be used as an R vector */ public static String objectArrayToRVector(Object[] rValues) { StringBuffer sb = new StringBuffer(R_VECTOR_START); if (rValues.length > 0) { // treat the 1st one as a special case (no comma) sb.append(rValues[0].toString()); // all the rest have commas for (int i = 1; i < rValues.length; i++) { sb.append(R_VECTOR_ELEMENT_SEPERATOR); sb.append(rValues[i].toString()); } } sb.append(R_VECTOR_END); return sb.toString(); } }