Using the parameter names of a function to defining variable names

时间:2017-10-03 11:56:55

标签: r function character

I'm new in the world of programming in R and I'm trying to understand the logic of such methods.

  1. I'm trying to get a solution to following situation:

    foo <- function(name){
        name <- sqlFetch(connection, name)
    }
    

    I want to write a function which is importing tables from a database and names the imported table like its name in the database. E.g: If I want to import the table "cars" this table in R should also called cars.

    How is it possible to write such a function? This should just be a the first part of my function.

  2. I have another really simple regarding character as parameters of my function like table names or something. As argument I'm using the name enclosed of quotes. i.e. "cars" and not cars. Are the quotes included if the function replaces the parameter?

    I'm asking because in the sqlFetch you have to place the table names in quotation marks. So which type of function would be correct, the upper one or the following:

    foo <- function(name){
        name <- sqlFetch(connection,"name")
    }
    

0 个答案:

没有答案