RLink`
RLink`

RList

RList[{elems},attributes]

represents an internal form of an R list in RLink.

更多信息和选项

  • The elements elems can be of any valid RLink object type.
  • attributes must have the form RAttributes["name1":>value1,...], where values of attributes can be any R objects handled by RLink.

范例

基本范例  (9)

Like with RVector, most of the time, you will find it more convenient to use the short form of a list, rather than using RList directly. For example, a pair of an integer and a real number can be represented simply as:

Yo can use ToRForm to see the internal form of this list, which would involve RList:

One reason to use the head RList explicitly is when you want to treat some data as a list, which the automatic type detection of RLink would otherwise classify as a vector. For example, consider the following nested list:

It will be considered as a vector by default:

To force the list interpretation, you can use the following instead:

It is now interpreted as a list:

The same will also happen for a flattened list of data:

The confusion can only happen for lists representing regular arrays. Ragged lists are always interpreted as R lists:

You can always check yourself with FromRForm function: the call to ToRForm followed by the call to FromRForm should produce back the short form of your input:

As with RVector, you can send instances of RList directly to R:

You can always check what was sent to R by using REvaluate:

Also, as with RVector, the case when you assign some extra attributes is treated differently. Consider the following example:

The short (involving only lists) form of Mathematica representation of your R object is no longer possible, since you have to store the attributes somewhere:

Note that the same ambiguity can happen here as well:

As you can see, lists were interpreted as vectors here. Here is the form that will force the list interpretation in this case:

Now the lists will be interpreted as R lists rather than R vectors:

Here is an example of a more complex list:

You can see that generally, it is a lot easier to work with the above short form than with a full internal form:

Either form can be sent to R:

You can check that they are the same in R:

Which, of course, means that they are the same when pulled back to Mathematica:

This is a bit tangential to the present discussion, but there are two types of indexing possible for lists in R. Here is an example of the one with the same syntax as array indexing:

It provides an R list with a given element. The other one is the one with the double square bracket syntax, and it truly extracts the element:

This is reflected on the Mathematica side by the first result being wrapped in an extra List. This is also consistent with the conversion to the internal RLink form:

You should keep this difference in mind when working with R lists in RLink.

Wolfram Research (2012),RList,Wolfram 语言函数,https://reference.wolfram.com/language/RLink/ref/RList.html.

文本

Wolfram Research (2012),RList,Wolfram 语言函数,https://reference.wolfram.com/language/RLink/ref/RList.html.

CMS

Wolfram 语言. 2012. "RList." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/RLink/ref/RList.html.

APA

Wolfram 语言. (2012). RList. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/RLink/ref/RList.html 年

BibTeX

@misc{reference.wolfram_2024_rlist, author="Wolfram Research", title="{RList}", year="2012", howpublished="\url{https://reference.wolfram.com/language/RLink/ref/RList.html}", note=[Accessed: 18-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_rlist, organization={Wolfram Research}, title={RList}, year={2012}, url={https://reference.wolfram.com/language/RLink/ref/RList.html}, note=[Accessed: 18-November-2024 ]}