Calculate total number of arguments enter into the function

If i am making a function in R and i want to print how many character i have entered into an argument, please tell me how to make this function. Just to simply calculate and print the total number of characters are there in my argument or in my input

I believe what you're looking for is nchar:

f <- function(x) {
    nchar(x)
}

f("apple")

2 Likes

Thankyou so much, but what if i want my argument as a string but not a character, also i want my input without any gap or commas.

Can you provide a couple of examples of what you're looking for?

I am making a function in which it could calculate the total molecular weight of a protein. So, i have already entered or stored each molecular weights of every amino acids,

I want my function to read the argument or input like ABCDEF in this format. Please help me with this

This seems to be the same question you are posting in the two other threads. Please refrain from cross-posting the same question in different topics, per the community guidelines.

https://forum.posit.co/guidelines#keep-tidy

1 Like

Oops sorry, i will keep this in my mind