让R缩写为用户提供的函数参数的字符输入

时间:2017-05-15 19:04:43

标签: r function text character

背景:

我有一个名为abs的R函数。该函数只有一个名为main.name的参数。此函数的用户在引号中提供字符类型名称(例如,"Length of Residence"),函数abs使用此用户提供的名称作为简单图表的主标题。

问题

用户可以提供非常长的名称(例如,"Oral Language Ability of Minors")。要克服这个问题:

我想知道当用户提供超过2个单词的 a main.name 时,R会选择每个单词的第一个字符并制作一个main.name的“缩写”?

例如,在这种像差之后,"Oral Language Ability of Minors"变为“OLAOM”。

abs = function (main.name) {

plot(rnorm(1e2), main = main.name)

} 

abs ("Oral Language Ability of Minors")

1 个答案:

答案 0 :(得分:2)

你可以做这样的事情

// This is a manifest file that'll be compiled into application.js, which will 

    include all the files
    // listed below.
    //
    // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
    // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
    //
    // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
    // compiled file. JavaScript code in this file should be added after the last require_* statement.
    //
    // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
    // about supported directives.
    //
    //= require jquery
    //= require jquery_ujs
    //= require bootstrap
    //= require turbolinks
    //= require_tree .